Skip to content

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

Description

@qwbarch

As a quick and dirty test I tried the following:

  runPyInMain [pymain| import asyncio|]
  foo 
    runPyInMain
      [pyf|
      async def foo():
        print("running foo")
        await asyncio.sleep(10)
        print("ending foo")
      
      return foo
      |]
  _ 
    forkIO $
      runPy
        [py_|
        asyncio.run(foo_hs())
        |]
  _ 
    forkIO $
      runPy
        [py_|
        asyncio.run(foo_hs())
        |]

This causes the second thread to wait until the first thread to run its async function (as expected since it's waiting for the global lock). However, top-level async calls are not supported so I can't seem to be able to call async functions from multiple places without it blocking the global lock.

Is it possible run multiple async functions at the same time, but calling it from the Haskell side?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions