multithreading - Python thread class - exiting threads -



multithreading - Python thread class - exiting threads -

i using thread invoke function runs :

def filliq(ipno): global inp_width global no_exit try: while 1 : if no_exit==1: sys.exit() # <exit line> tags=[] in range(ipno): yn=random.randint(0,1) if yn==1: voqno=random.randint(0,ipno-1) if inpq[i][voqno]<10: inpq[i][voqno]+=1 tag="iq" tags.append(tag) d.update() time.sleep(2) d.delete("iq") drawiq(ipno) except baseexception ,e: print "filliq > "+e

i changing value of no_exit in main function. 1 time alter thread not getting exit. because next time create thread instance different inputs( gui program. 1 input execute thread , later, alter input , execute again) odler thread appears run.

to exit thread must either homecoming or raise systemexit(). returning raises systemexit exception in context of thread. catching exception , not re-raising it.

>>> isinstance(systemexit(1), baseexception) true

there's problem. either grab systemexit exceptions separately , re-raise explicitly, or more selective general catching, or re-raise everything catch. brevity, give illustration of former

except systemexit: raise except baseexception: print "filliq > ", e

also, note it's , e , not +e since e not string. there couple of other issues encountered trying thread run, i'm sure you'll figure them out enough, missing imports , other values not listed in example.

python multithreading

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -