摘要:
# -*- coding: utf-8 -*- import os from socket import * from multiprocessing import Process def talk(conn): while 1: # 循环通讯 try: from_client_msg = conn 阅读全文
posted @ 2019-06-16 23:55
lilyxiaoyy
阅读(1749)
评论(0)
推荐(0)
摘要:
# -*- coding: utf-8 -*- import threading from socket import * from threading import Thread def talk(conn): while 1: # 循环通讯 try: from_client_msg = conn 阅读全文
posted @ 2019-06-16 23:51
lilyxiaoyy
阅读(2132)
评论(0)
推荐(0)
摘要:
# -*- coding: utf-8 -*- from gevent import monkey; monkey.patch_all()import gevent from socket import * def talk(conn): while 1: # 循环通讯 try: from_clie 阅读全文
posted @ 2019-06-16 23:45
lilyxiaoyy
阅读(563)
评论(0)
推荐(0)
摘要:
协程 在一个线程中并发执行多个任务,当遇到IO操作的时候,自动切换到其他任务去执行。 gevent 是第三方的一个模块,需要手动安装pip install gevent先看一个例子 from gevent import monkey monkey.patch_all() # 记住一定放在第一行,这里 阅读全文
posted @ 2019-06-16 23:21
lilyxiaoyy
阅读(1321)
评论(0)
推荐(1)
摘要:
pip install greenlet # -*- coding: utf-8 -*- from greenlet import greenlet def func1(): print("func1 first") gr2.switch() print("func2 second") gr2.sw 阅读全文
posted @ 2019-06-16 22:42
lilyxiaoyy
阅读(832)
评论(0)
推荐(0)
摘要:
# -*- 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 阅读全文
posted @ 2019-06-16 22:41
lilyxiaoyy
阅读(242)
评论(0)
推荐(0)
摘要:
# -*- coding: utf-8 -*- import queue if __name__ == '__main__': '''先进先出''' que = queue.Queue(3) que.put("first") que.put("second") que.put(["a", "b", 阅读全文
posted @ 2019-06-16 19:59
lilyxiaoyy
阅读(1135)
评论(0)
推荐(0)
摘要:
# -*- coding: utf-8 -*- from threading import Timer def talk(name): print("%s is talking." % name) if __name__ == '__main__': '''Timer(等待多少秒, 执行的函数, a 阅读全文
posted @ 2019-06-16 19:45
lilyxiaoyy
阅读(4160)
评论(0)
推荐(0)
摘要:
# -*- coding: utf-8 -*- import time import threading from threading import Thread, Event def conn_mysql(): '''连接数据库''' print("(%s) start to conn_mysql 阅读全文
posted @ 2019-06-16 19:40
lilyxiaoyy
阅读(1129)
评论(0)
推荐(0)
摘要:
# -*- coding: utf-8 -*- import time from threading import Thread, Semaphore def go_ktv(i): print("user%s正在....ktv." % (i)) time.sleep(2) if __name__ = 阅读全文
posted @ 2019-06-16 18:05
lilyxiaoyy
阅读(1215)
评论(0)
推荐(0)
摘要:
GIL锁(Global Interpreter Lock)全局解释器锁 在Cpython解释器中,同一进程下开启的多线程,同一时刻只能有一个线程执行,无法利用多核优势.那么,我们改如何解决GIL锁的问题呢? 1.更换cpython为jpython(不建议) 2.使用多进程完成多线程的任务 3.在使用 阅读全文
posted @ 2019-06-16 16:39
lilyxiaoyy
阅读(366)
评论(0)
推荐(0)
浙公网安备 33010602011771号