[Tutor] quick question about threads
Kent Johnson
kent37 at tds.net
Wed Jan 18 03:53:33 CET 2006
nephish wrote:
> Hey there, i have a program written in python that uses four threads
> that run all at the same time. Now i want to add a new thread with the
> same basic structure (threading.thread) that will run only when needed.
> This one will not run in a loop, it will just run once and quit.
> So, i may need this to be running several times at once because it will
> have a 15 second delay written into it.
> My question is, after the script is done, will it be safe ? i mean, over
> the course of a few days, it may run this thing a few hundred times. if
> it is simple like this
>
> threading.thread
> print 'here is something to say'
> time.sleep(15)
> print 'here is something else'
>
> do i need to include a special command to kill the thread, or will it
> just finish and everything will be ok then ?
Assuming you are showing the run() method of your thread above, it
should be fine. If the run() method exits the thread terminates and you
don't have to worry about it any more. Make sure you don't keep any
references to the threads so they can be garbage-collected.
Kent
More information about the Tutor
mailing list