try/finally in threads

George Sakkis george.sakkis at gmail.com
Mon Jul 2 22:49:59 EDT 2007


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 ?

George




More information about the Python-list mailing list