XtAppPending can block; this is a complex of X.org bugginess reported as http://bugs.freedesktop.org/show_bug.cgi?id=20048.
On recent Mac OS X (10.5.6 and 10.4.11+security update 2008-008), one of the problems results in an infloop in _XtWaitForSomething, the basic event gathering function for both XtAppPending and XtAppProcessEvent. I have no clue why, but under certain circumstances poll(2) will return with a fd in POLLNVAL state (ie, not open). _XtWaitForSomething ignores this, and loops looking for input, but I guess the POLLNVAL fd is at the head of the queue and never gets processed. (That's idle speculation, to be honest I really have no clue why this happens.)
The attached patch patch-NextEvent.c-XPOLL_EXCEPT teaches _XtWaitForSomething to notice this event, which fixes the infloop for me. I recommend application to MacPorts strongly (see the bug referenced above for rationale).
A second patch seems to me to be correct in principle, but it is neither necessary nor sufficient to fix the infloop. Since I've got it, Ill post it here for your consideration.
r47027