简体   繁体   English

Asyncio:具有事件循环用例的合法多线程?

[英]Asyncio: legitimate multiple threads with event loops use cases?

Granted, given the GIL, classic asyncio design should focus on "single main thread with single event loop" in it.诚然,考虑到 GIL,经典的asyncio设计应该关注其中的“单主线程和单事件循环”。 N.netheless, are there legitimate "multiple threads with multiple event loops" use cases, which bring some architectural or performance advantages over the singular case? N.尽管如此,是否存在合法的“具有多个事件循环的多线程”用例,这比单一用例带来了一些架构或性能优势? Please share.请分享。

I never compare the performance of using multiple event loop in multiple threads.我从不比较在多个线程中使用多个事件循环的性能。

As far as I know asynchronous is an event-driven architechture where single event loop is rely on single thread and the running function is this event-loop will wait for the trigger to get their time to run.据我所知, asynchronous是一种事件驱动的架构,其中单个事件循环依赖于单个线程,并且正在运行的函数是这个event-loop将等待触发器获得运行时间。 This would becomes faster than threading (in theory) since we're no longer taking care of resource management (memory, cpu etc).这将比线程(理论上)更快,因为我们不再负责资源管理(内存、cpu 等)。

Threading basically will try to manage the resource in terms to make them run concurrently because its actually switching the resource usage.线程基本上会尝试管理资源以使它们同时运行,因为它实际上会切换资源使用情况。

But both is proposed to execute the program in parallel even if its not concurrent at a time.但是两者都被提议并行执行程序,即使它一次不是并发的。 and for security, asynchronous is more thread safe since it's in a single thread.为了安全起见, asynchronous是线程安全的,因为它在单个线程中。

Found: one such use case is QEventLoop <-> asyncio.EventLoop "mutual stop-and-go hand-over" pattern in PySide6 , when QT event loop stops itself, then allows asyncio event loop to run for a while, then QT event loop is back in control, all the while sharing the same thread.发现:一个这样的用例是 PySide6 中的QEventLoop <-> asyncio.EventLoop “mutual stop-and-go hand-over” 模式,当PySide6事件循环停止自身时,然后允许QT事件循环运行asyncio时间,然后QT事件循环重新受到控制,同时共享同一个线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM