Skip to content

Add runPyAsync - #41

Draft
Shimuuar wants to merge 3 commits into
masterfrom
runAsync
Draft

Add runPyAsync#41
Shimuuar wants to merge 3 commits into
masterfrom
runAsync

Conversation

@Shimuuar

Copy link
Copy Markdown
Owner

This variant of runPy which executes python code in separate OS thread. Mostly useful for async in python

At the moment I'm not quite sure that API is right but it works with example in #40

Fixes #40

@qwbarch

qwbarch commented Aug 7, 2026

Copy link
Copy Markdown

If I'm understanding this right, a new OS thread is created every time runPyAsync is called right? Would it be better to instead have some sort of rpc-like communication and have the Python side run its tasks only on the event handler? I feel like this would be more similar in performance in calling a bunch of async functions in python compared to spawning a new OS thread for each call.

Just curious though, I don't know much about this so I'm interested in what your thoughts are!

@Shimuuar

Shimuuar commented Aug 7, 2026

Copy link
Copy Markdown
Owner Author

Yes. runPyAsync creates new OS thread. But since full haskell IO is allowed it's possible to construct any sort of thread pool. But only primitives are provided and drawing rest of the owl is left to library user

I think approach is workable but current implementation deadlocks readily. One have to be very careful about locking: liftIO should release GIL to allow other threads make progress. There's need to distinguish threads spawned by runPyAsync and rest. I didn't get around to actually implement that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is it possible to run python async functions in different Haskell threads?

2 participants