We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 4cf8bb0 + 196fc9c commit d2c1a9eCopy full SHA for d2c1a9e
source/c12/p01_start_stop_thread.rst
@@ -69,11 +69,11 @@ Python解释器直到所有线程都终止前仍保持运行。对于需要长
69
n -= 1
70
time.sleep(5)
71
72
- c = CountdownTask()
73
- t = Thread(target=c.run, args=(10,))
74
- t.start()
75
- c.terminate() # Signal termination
76
- t.join() # Wait for actual termination (if needed)
+ c = CountdownTask()
+ t = Thread(target=c.run, args=(10,))
+ t.start()
+ c.terminate() # Signal termination
+ t.join() # Wait for actual termination (if needed)
77
78
如果线程执行一些像I/O这样的阻塞操作,那么通过轮询来终止线程将使得线程之间的协调变得非常棘手。比如,如果一个线程一直阻塞在一个I/O操作上,它就永远无法返回,也就无法检查自己是否已经被结束了。要正确处理这些问题,你需要利用超时循环来小心操作线程。
79
例子如下:
0 commit comments