How do I get the function name when I create a new thread? #16408
hq1119418168
started this conversation in
General
Replies: 1 comment 1 reply
-
I do not know an easy way to get the function name directly. You can use import _thread as th
import time
def fun1(n):
...
print('ME:', th.get_ident(), tt[th.get_ident()])
tt.pop(th.get_ident())
def fun2(c,n):
...
print('ME:', th.get_ident(), tt[th.get_ident()])
tt.pop(th.get_ident())
tt = {}
tt[th.start_new_thread(fun1, (500,))] = 'fun1'
tt[th.start_new_thread(fun2, ('A', 3))] = 'fun2'
tt[th.start_new_thread(fun2, ('B', 7))] = 'fun2'
print('Threads:', tt)
# main thread wait until no more tasks
while tt: time.sleep(10)
print('All done!') |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
For example:
import _thread
def th_func1():
print('thread th_func1 is running')
_thread.start_new_thread(th_func1, ())
In mod_thread_start_new_thread, the th_func1 is passed in as a function pointer:
how do I get the string "th_func1"?
Beta Was this translation helpful? Give feedback.
All reactions