文中源码的线程和进程有本质区别是什么?傻傻分不清楚,文中源码,默认的get_event
文中源码的线程和进程有本质区别是什么?傻傻分不清楚,文中源码,默认的get_event
默认的get_event_loop获取的loop是基于线程还是进程,找了很久的官方文档才找到这么一句描述,看起来是属于当前线程的?
18.5.2.4. Event loop policies and the default policy
For most users of asyncio, policies never have to be dealt with explicitly, since the default global policy is sufficient. The default policy defines context as the current thread, and manages an event loop per thread that interacts with asyncio. The module-level functions get_event_loop() and set_event_loop() provide convenient access to event loops managed by the default policy.
那么官方文档提供的另外两个获取事件循环(下面的pre块)方法一般用于什么地方?关于事件循环尝试看了源码但涉及到多路IO复用问题遂放弃,求各位网友的指点?
loop = asyncio.new_event_loop()asyncio.set_event_loop(loop)
属于协程,即用户态线程,在单条内核线程上分出多个用户线程,本质还是单线程,算是一个高级语法糖,让你可以用同步的写法实现异步的效果(io多路复用维护起状态来是相当恶心的,现在交由asyncio来帮你维护了)
编橙之家文章,
相关内容
- Python装饰器这种用法可以吗,Python装饰器用法,class Ev
- Python sdk文档中尖括号如何处理,pythonsdk文档括号,比如
- 为什么读取通过cookielib方法得到的cookies返回值是空的
- 请教Python分布式实现一个helloworld的思路,pythonhellowor
- Python syslog模块怎么判断发送状态,pythonsyslog,syslog服务
- Python class Vector 的创建,pythonvector,创建一个向量的cla
- Python 源码中的re表达式同原生字符是怎么匹配成功的,
- Mac python2.7.3创建虚拟环境提示ImportError: No module named .
- PythonGIL与线程安全问题?,pythongil安全问题,由于一些历
- Pythom Scrapy框架Imagepipeline组件下载gif类型文件处理问题
评论关闭