Skip to content

Background Python operations can block the event loop #75

Open
@mmomtchev

Description

@mmomtchev

Consider the following scenario:

const q = pyCallable.callAsync(pyArg);
const b = somePyObject.attribute;
await q;

The first operation launches a Python operation in a background thread (using an existing thread in libuv's pool).
Python however is a single-threaded interpreter with a limited shared-memory multi-threading support - but not one which involves actually simultaneously interpreting Python code. Be sure to read Async in the wiki.

This means that the second line will effectively block the event loop until the first operation concludes.
A small, but notable exception to this rule is native Python extensions like numpy which release the Python GIL while running C code.

No Python object can be accessed while a Python background operation is running.

This is a fundamental Python limitation that is unlikely to go away in a foreseeable future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem rightwontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions