On Jun 12, 2013, at 11:40 AM, Jonathan Vanasco <twisted-pyt...@2xlp.com> wrote:

> Does anyone have a suggestion on how to best approach this ?  I saw some old 
> discussions about ideas for implementing graceful restarts via autoload, and 
> other stuff.

I'm not sure what "autoload" is.  I am assuming it's some kind of 
auto-re-loading technology though.

> Because my application might be in mid-conversation with external APIs , I 
> don't want to kill the process and respawn.

You do want to re-start your process.  What you're diagnosing is some weird, 
unknown thread/process interaction and unless you get a clean slate, you don't 
know what is happening.

You may not want to do so immediately, though, since, as you say:

> I'd like them to finish , and shutdown/restart N seconds later ( assuming 
> that I wouldn't be able to fully shutdown because of an issue with a locked 
> thread ).  

The issue is with letting them finish.  In order to accomplish this, you should 
write IService implementations that have stopService methods that, when called, 
will wait for any operations in flight associated with that service.

Once everything is quiesced, you can re-exec ([sys.executable] + sys.argv) and 
that ought to result in the same process starting up again.  If you've done the 
appropriate thing and made all your stopService methods wait for their 
operations to complete, then waiting for them all to complete is just putting 
them all into a MultiService, calling stopService() on that MultiService, and 
adding a callback/errback to the Deferred it returns which calls os.exec.

-glyph

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to