摘要: cpu在执行一个子线程的时候遇到sleep就会利用这段停顿时间去执行另一个子线程。两个子线程谁先跳出sleep就执行谁。 import threadingimport timestart = time.time()def foo(n): print("foo%s" % n) # 1执行 time.sleep(2) # 停2秒 print("foo执行结束") ... 阅读全文
posted @ 2018-09-06 22:35 Kay_xs 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 使用socketserver实现并发聊天 服务端可以比喻做一部电话。 ("127.0.0.1", 8000) 比喻做服务端的一个号码。 1,server.py 2, client.py 阅读全文
posted @ 2018-09-06 14:25 Kay_xs 阅读(191) 评论(0) 推荐(0) 编辑