2016-04-19 18:03:26 +01:00
|
|
|
# test _thread.get_ident() function
|
|
|
|
#
|
|
|
|
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
|
|
|
|
|
|
|
|
import _thread
|
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2023-08-03 21:20:30 +01:00
|
|
|
tid = None
|
|
|
|
|
|
|
|
|
2016-04-19 18:03:26 +01:00
|
|
|
def thread_entry():
|
2023-08-03 21:20:30 +01:00
|
|
|
global tid
|
2016-04-19 18:03:26 +01:00
|
|
|
tid = _thread.get_ident()
|
|
|
|
print("thread", type(tid) == int, tid != 0, tid != tid_main)
|
2016-04-21 13:38:22 +01:00
|
|
|
global finished
|
|
|
|
finished = True
|
2016-04-19 18:03:26 +01:00
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2016-04-19 18:03:26 +01:00
|
|
|
tid_main = _thread.get_ident()
|
|
|
|
print("main", type(tid_main) == int, tid_main != 0)
|
|
|
|
|
2016-04-21 13:38:22 +01:00
|
|
|
finished = False
|
2023-08-03 21:20:30 +01:00
|
|
|
new_tid = _thread.start_new_thread(thread_entry, ())
|
2016-04-19 18:03:26 +01:00
|
|
|
|
2016-04-21 13:38:22 +01:00
|
|
|
while not finished:
|
|
|
|
pass
|
2023-08-03 21:20:30 +01:00
|
|
|
|
|
|
|
print("done", type(new_tid) == int, new_tid == tid)
|