>  Q&A  >  본문

linux - Python中aysncio的事件循环是属于线程还是进程?

默认的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)
伊谢尔伦伊谢尔伦2740일 전817

모든 응답(1)나는 대답할 것이다

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:25:05

    단일 커널 스레드에서 여러 사용자 스레드를 분할하는 사용자 모드 스레드인 코루틴에 속합니다. 이는 기본적으로 동기 쓰기를 사용하여 달성할 수 있는 고급 구문 설탕입니다. 비동기 효과(io 다중 채널 재사용 및 유지 관리 상태가 상당히 역겨워서 이제 asyncio 유지 관리에 도움을 주어야 합니다.)

    회신하다
    0
  • 취소회신하다