Re: daemon thread cleanup approach

2014-05-30 Thread Devin Jeanpierre
On Fri, May 30, 2014 at 1:59 PM, Ethan Furman wrote: > Given the use-case (must shut down, cannot risk a hung process, orphan files > be damned) I don't think having a daemon thread die because it raised an > exception trying to access a missing global is a big deal. It's certainly suboptimal. Su

Re: daemon thread cleanup approach

2014-05-30 Thread Ethan Furman
On 05/30/2014 01:47 PM, Devin Jeanpierre wrote: Don't use daemon threads, they are inherently un-thread-safe: any global access you do anywhere inside a daemon thread can fail, because daemon threads are still potentially run during interpreter shutdown, when globals are being deleted from every

Re: daemon thread cleanup approach

2014-05-30 Thread Devin Jeanpierre
Don't use daemon threads, they are inherently un-thread-safe: any global access you do anywhere inside a daemon thread can fail, because daemon threads are still potentially run during interpreter shutdown, when globals are being deleted from every module. Most functions you might call are not safe

Re: daemon thread cleanup approach

2014-05-29 Thread Carl Banks
On Thursday, May 29, 2014 1:15:35 AM UTC-7, Chris Angelico wrote: > On Thu, May 29, 2014 at 11:20 AM, Carl Banks wrote: > > > Most threads have cleanup work to do (such as deleting temporary > > directories and killing spawned processes). > > > > > > For better or worse, one of the requirement

Re: daemon thread cleanup approach

2014-05-29 Thread Chris Angelico
On Thu, May 29, 2014 at 11:20 AM, Carl Banks wrote: > Most threads have cleanup work to do (such as deleting temporary directories > and killing spawned processes). > > For better or worse, one of the requirements is that the library can't cause > the program to hang no matter what... This ma y

Re: daemon thread cleanup approach

2014-05-28 Thread Cameron Simpson
On 28May2014 18:20, Carl Banks 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 a

Re: daemon thread cleanup approach

2014-05-28 Thread Miki Tebeka
Greetings, > Ok, so I have an issue with cleaning up threads upon a unexpected exit. What do you mean by "unexpected exit"? Uncaught exception? SIGTERM? ... > Using atexit doesn't work because it's called after the daemon threads are > killed. I don't follow. Who is killing the daemon threads?

daemon thread cleanup approach

2014-05-28 Thread Carl Banks
Ok, so I have an issue with cleaning up threads upon a unexpected exit. I came up with a solution but I wanted to ask if anyone has any advice or warnings. Basically I am writing a Python library to run certain tasks. All of the calls in the library start worker threads to do the actual work,