setDaemon problem.

Ramashish Baranwal ramashish.lists at gmail.com
Fri Apr 20 04:17:09 EDT 2007


Hi,

I am facing an issue in daemonizing a thread using setDaemon method.
Here is my code-

import time
from threading import Thread

class MThread(Thread):
    def run(self):
        f = open('/tmp/t.log', 'w')
        for i in range(10):
            f.write('Iteration %d\n' % i)
            time.sleep(1)
        f.close()

if __name__ == "__main__":
    t = MThread()
    t.setDaemon(True)
    print 'Starting thread'
    t.start()

The scripts runs all fine, but nothing gets logged to "/tmp/t.log".
However when I run the same script without setting thread as daemon
(no call to t.setDaemon), everything works fine.

Am I missing anything?

Thanks in advance,
Ram




More information about the Python-list mailing list