简体   繁体   中英

Why run_in_executor placed in BaseEventLoop?

For example, asyncio.gather has signature asyncio.gather(*coros_or_futures, loop=None, return_exceptions=False) .

I can pass specific loop or leave None (and default event loop will be used).

Why doesn't BaseEventLoop.run_in_executor defined same way, like: asyncio.run_in_executor(executor, callback, *args, loop=None) ?

If there was some important reason to place it into BaseEventLoop ?

Historically run_in_executor appeared very early and it was an event loop's method. It's modeled after twisted's methods for running code in thread pool. After appearing the run_in_executor has never changed. It's low-level function, that accepts callback and sits pretty close to other functions which accepts callback, not couroutine: call_soon() , call_later() , add_reader() etc. All those are methods of event loop.

asyncio.gather was invited much later, after about a year of the library development. It is placed on higher abstraction level, works with coroutines and pushed along with other coroutine-related functions like wait() or sleep() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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