try/finally in threads

G

George Sakkis

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
 
D

Diez B. Roggisch

George said:
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
 
G

George Sakkis

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top