newbie in threading

Stefan Antoni sasoft at gmx.de
Mon Nov 19 18:13:01 CET 2001


i am a total newbie in threading.
i got some questions to verify if i understood some
aspects of threads.

1. threads will never terminate in python, the'll live 
   on during the whole runtime,
   but i can modify them to be inactive using an "threading.Event"
   if i doesn't have any work for this thread further on(?)
 
   some code which does that from another listmember 1-2 days before:

### [code ###

import threading
import time

def mythread(killevent):
	# checkt ob Event.isSet == true und führt sollange
	# print und sleep aus. wenn isSet == true wird der
	# thread "inaktiv" (terminieren kann man einen thread
	# nie ganz)
	while not killevent.isSet():
		print "thread running" 
		time.sleep(2)

killevent = threading.Event() # das event für den thread erstellen
thread = threading.Thread(None, mythread, "", (killevent,)) # thread erstellen und event reingeben
thread.start()

time.sleep(6)
killevent.set() # das killevent setzen damit der thread beeinflusst wird
thread.join() # thread synchronisieren(?) zum sauberen beenden

### code] ###

2. what does thread.join exactly?

3. is a bunch of inactive threads able to slow down my program, or will
   the gc clean them up for me? should i do a "del myThread" for saving
   memory?
   are there any other ways to terminate a thread?

-- 
thx in advance,
stefan antoni

	 /"\
	 \ /     ASCII Ribbon Campaign
	  X      Against HTML Mail
	 / \





More information about the Python-list mailing list