摘要: import threading import time def func(n): time.sleep(0.5) n += 1 print(n, threading.current_thread(), threading.get_ident()) for i in range(10): threading.Thread(target=func, args... 阅读全文
posted @ 2018-10-21 16:25 aaronthon 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 我们使用高并发,一次是创建1万个线程去修改一个数并打印结果看现象: 我们可以看到,虽然是高并发,但是没有一条数据是重复的,为什么?因为Python解释器里面有全局解释器锁GIL,会让解释器每一时刻只有一个线程在运行,这样就保证了数据的安全了。 从这里我们也看出了,因为有全局解释器锁的存在就导致代码的 阅读全文
posted @ 2018-10-21 13:34 aaronthon 阅读(117) 评论(0) 推荐(0) 编辑