This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Thread in threading.py can only be started once
Type: enhancement Stage:
Components: None Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, christian.heimes, skip.montanaro, spiv, tim.peters, yahoo_alive
Priority: normal Keywords:

Created on 2003-06-09 10:16 by yahoo_alive, last changed 2022-04-10 16:09 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
thread.py yahoo_alive, 2003-06-09 10:16 example
Messages (8)
msg53904 - (view) Author: Lars Schuenzel (yahoo_alive) Date: 2003-06-09 10:16
class Thread doesn't reset self.__started after run() has terminated, so one cannot reuse 
the thread class and run start() again.
msg53905 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-06-09 22:54
Logged In: YES 
user_id=31435

It's true that Thread instances can't be restarted, but you 
haven't made a case for calling that "a bug".  Python's 
threading model is fashioned loosely on Java's, and, like 
Java's, limits thread instances to one invocation by design.
msg53906 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-06-15 03:56
Logged In: YES 
user_id=357491

I agree with Tim here.  I don't see a need for this anyway.  Once 
a thread has terminated it is done, period.  Having to 
reinstantiate a class to run another thread is perfectly 
reasonable.
msg53907 - (view) Author: Lars Schuenzel (yahoo_alive) Date: 2003-06-15 11:22
Logged In: YES 
user_id=647640

Maybe I should state some reasons for adding this functionality:

Imagine, you wish your thread to do some background work
while normal execution goes on (e.g. parsing a website).
It's a small task doing execatly the same job over an over.
If that will happen often, the overhead of creating a new
object might be too hight, especially if your object holds a
lot of data. And sometime the garbage collector will kick in...
If you want to write a really small class build from several
mix-in classes and Thread that only seldom needs to run
start(), you could use all member functions and variables.
Nice and neat.
And last but not least it wouldn't break compatibility.
Programs using threadying.py needn't change a single line.
There are more pro's and con's to this. To my opinion it is
more a matter of coding style and design. I do not know
Java's threads but I agree now with time_one: maybe this
issue is more a feature request than a bug report.
msg53908 - (view) Author: Andrew Bennetts (spiv) Date: 2003-06-15 12:35
Logged In: YES 
user_id=50945

> Imagine, you wish your thread to do some background work
> while normal execution goes on (e.g. parsing a website).
> It's a small task doing execatly the same job over an over.
> If that will happen often, the overhead of creating a new
> object might be too hight, especially if your object holds a
> lot of data. And sometime the garbage collector will kick
in...

Asking for this feature on the basis of performance sounds
bogus to me.  I'd expect creating and finishing threads to
be more expensive than the usual way to do this, which is to
have the one thread process chunks of work delivered via a
Queue.Queue (as opposed to creating a short-lived thread for
each chunk of work).

If you really think performance is the issue here, do some
benchmarking of the way things work at the moment versus
your proposal, versus long-lived threads using Queues.  If
you have some compelling numbers, then you'll have more
chance of convincing people this needs to be done.  (But my
guess is you'll find long-lived threads are more efficient.)
msg53909 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-06-15 21:03
Logged In: YES 
user_id=357491

What Andrew said.  =)  Although I realize if you did already know 
how to make this work you would have made this a patch.

I am reclassifying this as a feature request instead of a bug since 
the code isn't broken; you just want it to do something that it is 
not designed to do at the moment.
msg55403 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2007-08-29 01:45
Closing as won't fix.  Python's threads work
as designed.  There are plenty of solutions
available to get the desired behavior.
msg59333 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-05 20:56
Close it for real
History
Date User Action Args
2022-04-10 16:09:06adminsetgithub: 38613
2008-01-05 20:56:19christian.heimessetstatus: open -> closed
nosy: + christian.heimes
messages: + msg59333
2007-08-29 01:45:29skip.montanarosetnosy: + skip.montanaro
resolution: wont fix
messages: + msg55403
2003-06-09 10:16:08yahoo_alivecreate