473,503 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setDaemon problem.

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

Apr 20 '07 #1
6 3978
Ramashish Baranwal schrieb:
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?
Yes. You miss the documentation of setDaemon. It is _not_ a
PROCESS-daemonization recipe - which you can get here:

http://aspn.activestate.com/ASPN/Coo...n/Recipe/66012

Instead, it means that the thread started is considered not to be worth
waiting for when the main thread exits. Which it does immediately in
your code, resulting in nothing written in the logfile.

I think the name setDaemon is somewhat unfortunate.
Diez
Apr 20 '07 #2
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?

Yes. You miss the documentation of setDaemon. It is _not_ a
PROCESS-daemonization recipe - which you can get here:

http://aspn.activestate.com/ASPN/Coo...n/Recipe/66012

Instead, it means that the thread started is considered not to be worth
waiting for when the main thread exits. Which it does immediately in
your code, resulting in nothing written in the logfile.

I think the name setDaemon is somewhat unfortunate.
Thanks Diez,

I was also wondering about "daemonizing" a thread, but I interpreted
that it would daemonize the process which it didn't. I think setDaemon
should be renamed to setDetached or something similar.

Ram

Apr 20 '07 #3

"Ramashish Baranwal" <ra*************@gmail.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...
I was also wondering about "daemonizing" a thread, but I interpreted
that it would daemonize the process which it didn't. I think setDaemon
should be renamed to setDetached or something similar.
Neither is particularly intuitive; it just depends whether you are more
familiar with the Posix terminology or the Java one. I personally prefer
detached but there is little chance of a name change now.
Apr 20 '07 #4
Richard Brodie wrote:
"Ramashish Baranwal" <ra*************@gmail.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...
>I was also wondering about "daemonizing" a thread, but I interpreted
that it would daemonize the process which it didn't. I think setDaemon
should be renamed to setDetached or something similar.

Neither is particularly intuitive; it just depends whether you are more
familiar with the Posix terminology or the Java one. I personally prefer
detached but there is little chance of a name change now.
Why not? That's what Python 3.0 is for.
--
Michael Hoffman
Apr 20 '07 #5

"Michael Hoffman" <ca*******@mh391.invalidwrote in message
news:f0**********@gemini.csx.cam.ac.uk...
>Neither is particularly intuitive; it just depends whether you are more
familiar with the Posix terminology or the Java one. I personally prefer
detached but there is little chance of a name change now.

Why not? That's what Python 3.0 is for.
I think you need a better reason than: "it's mildly confusing to people, if
they don't read the manual" for an API change; but that's just my opinion.
Apr 20 '07 #6
Richard Brodie wrote:
"Michael Hoffman" <ca*******@mh391.invalidwrote in message
news:f0**********@gemini.csx.cam.ac.uk...
>>Neither is particularly intuitive; it just depends whether you are more
familiar with the Posix terminology or the Java one. I personally prefer
detached but there is little chance of a name change now.
Why not? That's what Python 3.0 is for.

I think you need a better reason than: "it's mildly confusing to people, if
they don't read the manual" for an API change; but that's just my opinion.
One of the goals of Python 3.0 is to clean up previous warts in the
language, and there will be a number of API changes. And one of the good
things about Python in general is that things frequently can be
understood without reading a manual. I think anything to aid this should
be encouraged.
--
Michael Hoffman
Apr 20 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3046
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
11
3733
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
0
2009
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent...
9
2216
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application...
117
7102
by: Peter Olcott | last post by:
www.halting-problem.com
28
5170
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
3785
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
4870
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
4531
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.