摘要:
# -*- coding: utf-8 -*- import time def consumer(item): time.sleep(0.01) pass def producer(target, seq): for item in seq: target(item) start_time = ti 阅读全文
摘要:
# -*- coding: utf-8 -*- import queue if __name__ == '__main__': '''先进先出''' que = queue.Queue(3) que.put("first") que.put("second") que.put(["a", "b", 阅读全文
摘要:
# -*- coding: utf-8 -*- from threading import Timer def talk(name): print("%s is talking." % name) if __name__ == '__main__': '''Timer(等待多少秒, 执行的函数, a 阅读全文
摘要:
# -*- coding: utf-8 -*- import time import threading from threading import Thread, Event def conn_mysql(): '''连接数据库''' print("(%s) start to conn_mysql 阅读全文
摘要:
# -*- coding: utf-8 -*- import time from threading import Thread, Semaphore def go_ktv(i): print("user%s正在....ktv." % (i)) time.sleep(2) if __name__ = 阅读全文
摘要:
GIL锁(Global Interpreter Lock)全局解释器锁 在Cpython解释器中,同一进程下开启的多线程,同一时刻只能有一个线程执行,无法利用多核优势.那么,我们改如何解决GIL锁的问题呢? 1.更换cpython为jpython(不建议) 2.使用多进程完成多线程的任务 3.在使用 阅读全文