try/finally in threads
George Sakkis
george.sakkis at gmail.com
Tue Jul 3 15:13:32 EDT 2007
On Jul 3, 5:05 am, "Diez B. Roggisch" <d... at nospam.web.de> wrote:
> George Sakkis wrote:
> > I posted this on the Pyro list but I'm not sure if it's related
> > specifically to Pyro. The "finally" clause below is not executed when
> > f() runs on on a (daemon) thread and the program exits. DAEMON here is
> > a global Pyro.code.Daemon instance.
>
> > def f():
> > try: DAEMON.requestLoop()
> > finally:
> > # nothing is printed if f() runs in a thread
> > print "i am here!!"
> > DAEMON.shutdown()
> > print "i am over!!"
>
> > Is "finally" not guaranteed to be executed in a non-main thread or is
> > there something else going on ?
>
> Well, that's pretty much the idea behind daemon threads - that they are
> terminated immediately. If it were otherwise, a little endless-loop in that
> finally-statement of yours would cause the program termination to hang
> endlessly.
Thanks, that makes sense; if the thread is non-daemon, it enters the
finally block as expected.
George
More information about the Python-list
mailing list