20 lines
365 B
Python
Raw Normal View History

2023-04-15 11:20:11 +08:00
import time
import _thread
finished = False
2023-04-20 19:26:04 +08:00
def test_thread(arg):
2023-04-15 11:20:11 +08:00
global finished
for i in range(3):
print(i)
time.sleep(0.1)
finished = True
2023-04-20 19:26:04 +08:00
print('test_thread arg:', arg)
assert arg == 'test'
2023-04-15 11:20:11 +08:00
# 开启线程 获取数据
2023-04-20 19:26:04 +08:00
_thread.start_new_thread(test_thread, ('test'))
2023-04-15 11:20:11 +08:00
while not finished:
time.sleep(0.1)
time.sleep(0.1)