[Python-bugs-list] [ python-Bugs-793687 ] runnig thread multiple
times
SourceForge.net
noreply at sourceforge.net
Fri Aug 29 07:07:04 EDT 2003
Bugs item #793687, was opened at 2003-08-23 19:09
Message generated for change (Comment added) made by spiv
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=793687&group_id=5470
Category: Threads
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Grzegorz Makarewicz (makaron)
Assigned to: Nobody/Anonymous (nobody)
Summary: runnig thread multiple times
Initial Comment:
Internal variable __started remains set to True/1 even
if thread is already terminated, this situation will
generate assertion error when .start is invoked second
time.
demo.py
import time
import threading
done = threading.Event()
def demo():
print 'bip'
done.set()
t=threading.Thread(target=demo)
t.start()
while not done.isSet():
time.sleep(0.1)
done.clear()
print 'returned'
t.start()
----------------------------------------------------------------------
Comment By: Andrew Bennetts (spiv)
Date: 2003-08-29 23:07
Message:
Logged In: YES
user_id=50945
Also, how would 'someThread.join()' work if threads could be
restarted?
The current situation seems fine to me -- I can't think of a
use-case for this that isn't satisfied by either having an
idiomatic worker thread, or just simply creating a
completely new thread.
Presumably the rationale for wanting restartable threads is
performance, i.e. avoiding setup/teardown costs of threads
-- but this goal is better served by typical worker threads
blocking on a Queue.Queue anyway, i.e.:
def worker(queue):
while 1:
job = queue.get()
# ...
q = Queue.Queue()
t = threading.Thread(target=worker)
In my opinion, the current situation is fine and this
proposal isn't carefully thought out, so thsi bug can be
resolved as "won't fix".
[I seem to recall a bug very similar to this being rejected,
but I can't find it now]
----------------------------------------------------------------------
Comment By: Christos Georgiou (tzot)
Date: 2003-08-29 19:07
Message:
Logged In: YES
user_id=539787
This is documented behaviour, therefore not a bug (see
http://www.python.org/doc/current/lib/thread-objects.html ,
doc for the start() method).
The designed methodology is to create a new
threading.Thread object to start a new thread.
Why re-start a thread anyway? Optimisation of resources?
IMHO that would be minor, if existant at all.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=793687&group_id=5470
More information about the Python-bugs-list
mailing list