随笔分类 - python协/线/进程
摘要:Python对协程的支持是通过generator实现的 # 生产者send # 消费者yield 【yield不但可以返回一个值,它还可以接收调用者发出的参数】 def consumer(): r = '' while True: n = yield r if not n: return print
阅读全文
摘要:思路1,master等待远端返回结果 from multiprocessing import Pool import os, time, random # 在远端执行的任务进程,,hang住等待返回 def long_time_task(ip,url): print('Run task %s-%s
阅读全文
摘要:https://www.liaoxuefeng.com/wiki/1016959663602400/1017628290184064 join # 1. 一个 from multiprocessing import Process import os # 子进程要执行的代码 def run_proc
阅读全文
摘要:1.进程 守护进程随着主进程的代码结束而结束,注意是代码,主进程可能在等待其他的子进程 from multiprocessing import Process def func(): while True: time.sleep(0.2) print('OK') if __name=='__main
阅读全文
摘要:yield():释放当前cpu的执行权 join():在线程a中调用 线程b的 b.join(),此时线程a就进入阻塞状态,直到线程b完全执行完以后,线程a才结束阻塞状态。 daemon = True 主进程退出了,还能继续运行 without join: + + + main-thread | |
阅读全文
摘要:from threading import Thread from threading import Event import time class ChildThread(Thread): myStopSignal = 0 def __init__(self, aStopSignal): Thre
阅读全文
摘要:简单的函数封装 def thread_it(func, *args): t = threading.Thread(target=func, args=args) t.setDaemon(True) try: t.start() except Exception as e: raise e def c
阅读全文
摘要:区别【apply】【map】【apply_async】【map_async】 【map】各个进程执行顺序确定,当前进程阻塞 【map_async】各个进程执行顺序确定,当前进程不阻塞 【apply】各个进程执行顺序不确定,当前进程阻塞 【apply_async】各个进程执行顺序不确定,当前进程不阻塞
阅读全文
摘要:0.multiprocessing 多进程的使用 from multiprocessing import Pool, cpu_count import time build_links = [1,2,3,4,5,6,7,8] auth = 'auth' def test(url, auth): ti
阅读全文
浙公网安备 33010602011771号