Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background Python operations can block the event loop #75

Open
mmomtchev opened this issue Jan 21, 2023 · 0 comments
Open

Background Python operations can block the event loop #75

mmomtchev opened this issue Jan 21, 2023 · 0 comments
Labels
invalid This doesn't seem right wontfix This will not be worked on

Comments

@mmomtchev
Copy link
Owner

mmomtchev commented Jan 21, 2023

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.

@mmomtchev mmomtchev added invalid This doesn't seem right wontfix This will not be worked on labels Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant