Skip to content

uvloop run_in_executor prohibits coroutines (even if executor supports it) unlike asyncio run_in_executor #145

@autumnjolitz

Description

@autumnjolitz
  • uvloop version:
    uvloop==0.8.0
  • Python version:
    Python 3.6.2
  • Platform:
    OSX 16.7.0
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?:
    Yes.

Existing Asyncio in CPython master (snapshot permalink: https://github.com/python/cpython/blob/b7555babe95ee0db2f1224ec53cfe68a005448a1/Lib/asyncio/base_events.py#L724-L734) does not prohibit coroutines. I make use of this with a custom ProcessPoolExecutor that inits it's own private process event loop and runs coroutines as it encounters them, isolating out actual blocking synchronous tasks to a look aside process (for it to actually block on).

This following part:

uvloop/uvloop/loop.pyx

Lines 2307 to 2308 in b5aa30b

if aio_iscoroutine(func) or aio_iscoroutinefunction(func):
raise TypeError("coroutines cannot be used with run_in_executor()")

should be moved such that if executor is an instance of cc_ThreadPoolExecutor it raise TypeError("coroutines cannot be used with run_in_executor()") there. That will allow one to preserve safety for cc_ThreadPoolExecutor while allowing custom Executors to handle their support (or lack of) for coroutines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions