随笔分类 - ThreadAndProcess
摘要:服务器端:gevent_server.py 客户端:socket_client.py
阅读全文
摘要:import gevent def foo(): print("Running in foo") gevent.sleep(2) print("Explicit context switch to foo again") def bar(): print("Explicit context to bar") gevent.sleep(1 ) ...
阅读全文
摘要:高并发,单线程的实现上万并发不是问题
阅读全文
摘要:from multiprocessing import Pool import os,time def Foo(i): time.sleep(2) print("in process",os.getpid()) return i +100 def Bar(arg): print('-->exec done',arg,os.getpid()) if __na...
阅读全文
摘要:pipe.py#多进程数据传递接收和发送(类似socket) manger.py#多进程之间数据共享和传递(同时修改一份数据)
阅读全文
摘要:一、程序介绍 需求: 程序结构: 二、流程图 三、代码 目录结构: from_windows.py(待上传的文件) main.py(批量主机管理接口) core.py(核心代码,被接口调用) settings.py(配置文件) View Code 测试: 硬件限制,我只用连接一台虚拟机测试~ 上传前
阅读全文
摘要:队列最主要的两个作用: 1.解耦(松耦合) 2.提高效率
阅读全文
摘要:import time import threading event =threading.Event() def lighter(): count=0 event.set()#先设置成绿灯 while True: if count >5 and count10: event.set()#变绿灯 count=...
阅读全文
摘要:import threading,time def run(n): print("task is ",n) time.sleep(2) print("task done", n) start_time =time.time() t_objs = []#存线程实例 for i in range(50): t = threading.Thread(target=r...
阅读全文