codehz / bun_python

Ported from deno_python
MIT License
30 stars 1 forks source link

Release Python's Global Interpreter Lock #2

Closed heri16 closed 4 months ago

heri16 commented 4 months ago

Release Python's Global Interpreter Lock (GIL) when calling into JS Callbacks from Python.

Also release the GIL after each call into Python from JS, to allow python threading and multiprocessing library to function properly. See Python docs on Thread State and the Global Interpreter Lock.

This is also a prerequisite for reliable python3 asyncio support coming in future to bun_python.

heri16 commented 4 months ago

Fixes Issue #1

heri16 commented 4 months ago

All tests passing.

Kapture 2024-05-04 at 00 49 49

codehz commented 4 months ago

lgtm

heri16 commented 4 months ago

A bun test that checks if ThreadpoolExecutor is behaving correctly within bun_python would be nice to detect any regression in future.

https://docs.python.org/3/library/concurrent.futures.html#threadpoolexecutor

codehz commented 4 months ago
image

it seems doesn't work

codehz commented 4 months ago

I think it may related to bun's runtime behavior the thread may never working since you cannot fork the javascript core runtime