try/finally in threads
Diez B. Roggisch
deets at nospam.web.de
Tue Jul 3 05:05:08 EDT 2007
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.
Diez
More information about the Python-list
mailing list