multithreading - get thread ID or name in python 2.6 -


i trying thread id or name in python 2.6 follow examples errors global name 'currentthread' not defined global name 'current_thread' not defined

(i tried both currentthread , current_thread)

here code :

vim f3q.py   1 import queue   2 threading import thread   3   4 def do_work(item):   5         try:   6                 print current_thread().getname()   7   8   9         except exception details:  10                 print details  11                 pass  12         print item*2  13  14 def worker():  15         while true:  16                 item=q.get()  17                 do_work(item)  18                 q.task_done()  19  20 q=queue.queue()  21 l=[13,26,77,99,101,4003]  22 item in l:  23         q.put(item)  24  25  26 in range (4):  27         t=thread(target=worker,name="child"+str(i))  28         t.daemon=true  29         t.start()  30  31  32 q.join()  33 

update: fixed error hint mata gave should have imported current_thread() too.

from threading import thread,current_thread 

you haven't imported threading, thread.

either import threading, or import current_thread directly:

1 import queue 2 threading import thread, current_thread 3 4 def do_work(item): 5         try: 6                 print current_thread() 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -