On Wed, May 12, 2010 at 09:25:15AM -0700, Martine wrote: > I have recently upgraded to Ubuntu 10.04 from 9.10 and paster won't > shutdown cleanly anymore when I press Ctrl+C. It hangs forever at this > step: > > $ paster serve production.ini > Starting server in PID 9424. > serving on 0.0.0.0:8000 view at http://127.0.0.1:8000 > ^C2010-05-12 10:35:29 INFO [paste.httpserver.ThreadPool] Shutting > down threadpool > 2010-05-12 10:35:29 INFO [paste.httpserver.ThreadPool] All workers > stopped > > It turns out that it's hanging because of some worker threads.
Threads that you started manually, right? > I have tried creating a new project for testing with code from this > webpage, and the problem still happens: > http://chrismoos.com/2009/03/04/pylons-worker-threads/ It creates a non-daemon thread that runs forever. A Python process doesn't exit until all non-daemon threads exit. Incidentally, I do _not_ recommend changing your worker thread into a daemon thread; those have their own share of serious issues (could be terminated at any time, e.g. in the middle of a job, or could be running during interpreter shut down where all the global namespaces are cleared, resulting in really weird exceptions). The best solution is to trap the interpreter shutdown and explicitly signal your worker thread to quit. Something like QUIT = object() # unique marker object ... def run(self): while True: msg = worker_q.get() if msg is QUIT: break ... I don't know how to reliably trap the server shutdown, though. It depends on the particular server you're using to serve your WSGI app, I suppose. (For the same reason I'm also not sure it's safe to spawn threads from load_environment.) > I didn't have any problems before the upgrade to 10.04 so this is > pretty strange. Has anyone run into a similar problem? I'm not sure what could've changed with the Ubuntu 9.04 -> 10.04 upgrade; if you're using the default Python version (2.6 on both), I'd expect the same behaviour on both: i.e. process not exiting until all threads stop. Marius Gedminas -- Writing like a l33t script kiddie hax0r is the absolute kiss of death and guarantees you will receive nothing but stony silence (or, at best, a heaping helping of scorn and sarcasm) in return. -- ESR (http://www.tuxedo.org/~esr/faqs/smart-questions.html)
signature.asc
Description: Digital signature
