threading._start_new_thread executes twice?
Hari Sekhon
sekhon.hari at googlemail.com
Wed Jul 19 18:30:04 EDT 2006
I'm got a script which has a function with a while 1: loop that seems to
execute the line it's doing twice instead of just once on each pass when
called in a thread...
#Script Start
import threading,time,cherrypy
def func():
while 1:
print time.ctime()
time.sleep(30)
threading._start_new_thread( func,() )
class somename():
def index(self):
test="this is a test"
return test
index.exposed=True
cherrypy.root=somename()
cherrypy.config.update( file = cherrypy.conf )
cherrypy.server.start()
#end of script
(The contents of the cherrypy.conf is below: )
[global]
server.socketPort=8080
server.environment="development"
server.threadpool = 10
The output on the console is at follows
Wed Jul 19 23:25:34 2006
Wed Jul 19 23:25:34 2006
2006/07/19 23:25:34 CONFIG INFO Server parameters:
2006/07/19 23:25:34 CONFIG INFO server.environment: development
2006/07/19 23:25:34 CONFIG INFO server.logToScreen: True
2006/07/19 23:25:34 CONFIG INFO server.logFile:
2006/07/19 23:25:34 CONFIG INFO server.protocolVersion: HTTP/1.0
2006/07/19 23:25:34 CONFIG INFO server.socketHost:
2006/07/19 23:25:34 CONFIG INFO server.socketPort: 8080
2006/07/19 23:25:34 CONFIG INFO server.socketFile:
2006/07/19 23:25:34 CONFIG INFO server.reverseDNS: False
2006/07/19 23:25:34 CONFIG INFO server.socketQueueSize: 5
2006/07/19 23:25:34 CONFIG INFO server.threadPool: 0
2006/07/19 23:25:34 HTTP INFO Serving HTTP on http://localhost:8080/
Wed Jul 19 23:26:04 2006
Wed Jul 19 23:26:04 2006
Wed Jul 19 23:26:34 2006
Wed Jul 19 23:26:34 2006
If I just replace the threading._start_new_thread line with
func()
func()
func()
then the time is output only once every thrity seconds, so it seems that
threading._start_new_thread is calling func() twice initially?
Why is func() executing twice when called from the thread?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060719/e38eeade/attachment.html>
More information about the Python-list
mailing list