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?

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