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

Allow python threads and async io #1632

Merged
merged 4 commits into from
Jun 29, 2024
Merged

Allow python threads and async io #1632

merged 4 commits into from
Jun 29, 2024

Conversation

thommey
Copy link
Member

@thommey thommey commented Jun 29, 2024

Found by:
Patch by: thommey
Fixes:

One-line summary: Allows python to use threads and async io
Additional description (if needed):
Python threads were not given a chance to run in the background so far because we held onto the GIL.
Now we release it around our select() which should give Python threads or asyncio runners (in a separate thread) enough room to work.

The concern of having multithreaded code call into our Tcl interpreter against its will turns out to be unwarranted - the GIL takes care of this.

@thommey thommey marked this pull request as ready for review June 29, 2024 16:11
@thommey
Copy link
Member Author

thommey commented Jun 29, 2024

Test case 1 - Threads:

from eggdrop.tcl import putlog
from threading import Thread
from time import sleep

def tick():
    while True:
        putlog("thread running")
        sleep(.2)

thread = Thread(target = tick)
thread.start()

Test case 2 - Async IO with runner in separate Thread

from eggdrop.tcl import putlog
import asyncio
from threading import Thread

async def main():
    while True:
        putlog("asyncio running")
        await asyncio.sleep(.3)

def async_run():
    asyncio.run(main())

thread = Thread(target = async_run)
thread.start()

@vanosg vanosg merged commit ee8b2d3 into develop Jun 29, 2024
22 checks passed
@vanosg vanosg added the Python label Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants