Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72220
| Date | 2014-05-29 16:07 +1000 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: daemon thread cleanup approach |
| References | <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10439.1401343667.18130.python-list@python.org> (permalink) |
On 28May2014 18:20, Carl Banks <pavlovevidence@gmail.com> wrote: >Here's the solution I came up with: in the library's init function, it will start a non-daemon thread that simply joins the main thread, and then asks all existing worker threads to exit gracefully before timing out and leaving them to be killed. So if an exception ends the main thread, there is still a chance to clean up properly. > >Does anyone see a potential problem with this approach? It it possible that this will cause the program to hang in any case? We can assume that all calls to the library will occur from the main thread, or at least from the same thread. (If that isn't the case, then the caller has taken responsibility to ensure the program doesn't hang.) That sounds safe to me, unless any of the subthreads call some C-level library routine that hangs even in a daemon thread. Which I assume either isn't the case or isn't a bug addressable this way anyway. That's probably the best you can do from the sound of it, given that you may not hang (for longer than your timeout choice) and the calls are all at the whim of an external caller. BTW, what were your dislikes of the with statement? Disclaimer: I'm not a Windows guy. Cheers, Cameron Simpson <cs@zip.com.au>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
daemon thread cleanup approach Carl Banks <pavlovevidence@gmail.com> - 2014-05-28 18:20 -0700
Re: daemon thread cleanup approach Miki Tebeka <miki.tebeka@gmail.com> - 2014-05-28 22:51 -0700
Re: daemon thread cleanup approach Cameron Simpson <cs@zip.com.au> - 2014-05-29 16:07 +1000
Re: daemon thread cleanup approach Chris Angelico <rosuav@gmail.com> - 2014-05-29 18:15 +1000
Re: daemon thread cleanup approach Carl Banks <pavlovevidence@gmail.com> - 2014-05-29 12:40 -0700
Re: daemon thread cleanup approach Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-05-30 13:47 -0700
Re: daemon thread cleanup approach Ethan Furman <ethan@stoneleaf.us> - 2014-05-30 13:59 -0700
Re: daemon thread cleanup approach Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-05-30 14:58 -0700
csiph-web