Christopher Armstrong [radeex@gmail.com] wrote:
On Tue, 17 Aug 2004 20:34:44 -0400, twisted-10152003@atlas.lcs.mit.edu
wrote: I wrapped a c library using swig and was hoping to make use of it in a twisted server I am writing. The issue is that the c library fundamentally blocks waiting for input that may never come. Is there a way from twisted to deal with this cleanly within the framework?
I.e. some combination of adding a reactor.addSystemEventTrigger event and calling reactor.threadpool.stop seem like it should work but I haven't had any luck yet.
Try twisted.internet.threads.deferToThread(myBlockingCall) --> Deferred.
Ah, but that doesn't work. As I stated the c library (not mine) calls potentially block forever (or at least longer than I want to wait to shutdown the twisted server). The thread created by deferTothread may never complete which makes shutting down the server gracefully impossible (or so I thought?).
Geeze, where'd you come up with that stuff? Accessing reactor.threadpool directly is Really Bad. I hope there's no example code or documentation that refers to that.
:) Ah the hazards of attempting to read documentation and mailing-lists before posting... The threadpool and a link to its interface are mentioned on the primary threading howto. No mention of "Really Bad" there. http://www.twistedmatrix.com/documents/current/howto/threading And other posts about threading on this mailing list mentioned looking at twisted.enterprise.adbapi which is where reactor.addSystemEventTrigger ideas came from. Incidentally, I am happy to help update documentation if I can figure out the right ways to do things. :) Thanks for your rapid response. Sincerely, Steve Bauer