[Medusa-dev] medusa & asyncore.loop -- termination & GUI

Gregory P. Smith greg at electricrain.com
Wed Apr 9 18:08:21 EDT 2003


On Wed, Apr 09, 2003 at 04:57:48PM -0700, Hal Wine wrote:
> Hi, all -- I've been trying to figure out how to wrap a medusa based 
> app with a Tkinter GUI, and am stuck on clean termination. Seems like 
> this would have come up before, but I can't find anything.
> 
> What I want to do is allow timely and clean termination of the main 
> medusa based server from a GUI similar to the PyDoc GUI, in some ways.
> 
> This particular app has multiple calls to asyncore.loop 
> (multi-threaded), so removing them and replacing with a call from 
> Tkinter (ala the suggestion in the medusa/docs/tkinter.txt file) won't 
> work. The app still needs to work from the command line, unaltered.
> 
> There are two issues I need to resolve:
> 1) initiating a clean termination (can't type ^C to stop), and
> 2) responsiveness (default 30 second timeout is too long)
> 
> The options I've come up with seem too kludgy -- there must be a 
> simpler way. What I've thought of is:
> a) swap out asyncore.loop for my own hacked version
> b) push all of the orginal app into another thread, leaving the main 
> thread for the GUI
> c) have the threads raise an ExitNow exception based on a global flag.
> 
> (a) is the worst of it, as it's not robust across mods to asyncore. 
> It'd be great if there was a separate asyncore.get_poll_func() as part 
> of the API. Or an idle func that asyncore.loop would call on timeouts....
> 
> Any pointers to better/cleaner ideas welcomed.

(a) "make your own asyncore.loop"

Is actually a good option.  There is no reason that the event loop
shouldn't handle other events as well as socket I/O.  (look at
twistedmatrix.com's twisted-python library for example)

In virtually all of the asyncore based code I've written I've ended up
using my own version of the loop for very similar reasons.

-G



More information about the Medusa-dev mailing list