随笔 - 89,  文章 - 1,  评论 - 26,  阅读 - 90773
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
11 2017 档案
python select解析 socket高效通信服务器 自己写的socketserver
摘要:1 import select 2 import socket 3 import queue 4 5 server = socket.socket()#创建服务器端 6 server.bind(('localhost',9999))#绑定IP和端口 7 server.listen(1000)#参数为最大监听端口数量 8 server.setblocking(False)#设置为... 阅读全文
posted @ 2017-11-30 18:26 专注于区块链开发 阅读(458) 评论(0) 推荐(0) 编辑
python 多协程异步IO爬取网页加速3倍。
摘要:1 from urllib import request 2 import gevent,time 3 from gevent import monkey#该模块让当前程序所有io操作单独标记,进行异步操作。 4 5 monkey.patch_all()#对当前程序的io操作打上补丁。没有该monkey方法,异步IO无效。 6 def f(url): 7 print('... 阅读全文
posted @ 2017-11-29 19:01 专注于区块链开发 阅读(736) 评论(0) 推荐(0) 编辑
python gevent自动挡的协程切换。
摘要:1 import gevent 2 def func(): 3 print('running func 111')#第一步运行 4 gevent.sleep(2)#切换到下个协程 5 print('running func 111 agin')#最后一步执行。 6 def bar(): 7 print('running func 222')#第二部运... 阅读全文
posted @ 2017-11-29 17:57 专注于区块链开发 阅读(309) 评论(0) 推荐(0) 编辑
python 使用gevent模块实现手动挡切换多协程。
摘要:1 from greenlet import greenlet 2 3 def test1(): 4 print(12) 5 g2.switch()#切换到协程g2执行,保存执行状态 6 print(23) 7 g2.switch()#切换到协程g2执行,保存执行状态 8 print(34) 9 def test2(): 10 ... 阅读全文
posted @ 2017-11-29 17:29 专注于区块链开发 阅读(420) 评论(0) 推荐(0) 编辑
python 进程池的使用和坑
摘要:1 from multiprocessing import Pool,Process 2 import time,os 3 def Foo(a):#创建函数 4 time.sleep(2) 5 print('in the process:',os.getpid(),os.getppid()) 6 return a+100 7 8 def bar(arga... 阅读全文
posted @ 2017-11-29 12:12 专注于区块链开发 阅读(2716) 评论(0) 推荐(0) 编辑
python 进程之间的数据共享
摘要:1 from multiprocessing import Process,Manager 2 import os 3 def f(d,n): 4 d[os.getpid()] = os.getppid()#对字典d添加键值对,子进程:父进程 5 n.append(os.getpid())#将子进程添加到列表里。 6 7 if __name__ == '__mai... 阅读全文
posted @ 2017-11-29 08:37 专注于区块链开发 阅读(250) 评论(0) 推荐(0) 编辑
python 不同进程间通信
摘要:from multiprocessing import Process,Queue import os def f (qq): qq.put([42,None,'hello']) #将列表传入队列qq中 if __name__ == '__main__': q = Queue() #创建进程间通信专用Queue 如果使用线程queue则会出错。 p = Process(target=f,a... 阅读全文
posted @ 2017-11-28 17:42 专注于区块链开发 阅读(310) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示