Skip to content

Bug: Async JS Promise cannot find running Python event loop on Python 3.13 (Windows) #507

@LetuGitHub

Description

@LetuGitHub

Issue type

Bug

How did you install PythonMonkey?

None

OS platform and distribution

Windows 11 x64

Python version (python --version)

3.13.0

PythonMonkey version (pip show pythonmonkey)

1.3.1

Bug Description

When awaiting a JavaScript async function from Python using asyncio.run(), PythonMonkey raises:

RuntimeError: PythonMonkey cannot find a running Python event-loop to make asynchronous calls.

However, a Python event loop is clearly running and can be retrieved with:

print(asyncio.get_running_loop())

which outputs:

<ProactorEventLoop running=True closed=False debug=False>

This suggests that PythonMonkey is unable to access the currently running event loop internally, even though one exists.

Standalone code to reproduce the issue

import asyncio
import pythonmonkey as pm

async def async_fn():
    print(asyncio.get_running_loop())

    await pm.eval("""
        new Promise((resolve) => setTimeout((...args) => {
            console.log(args);
            resolve();
        }, 1000, 42, "abc")
        )
    """)
    await pm.eval("async (x) => await x")(asyncio.sleep(0.5))

asyncio.run(async_fn())

Relevant log output or backtrace

await pm.eval("""
          ~~~~~~~^^^^
        new Promise((resolve) => setTimeout((...args) => {
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        )
        ^
    """)
    ^^^^
RuntimeError: PythonMonkey cannot find a running Python event-loop to make asynchronous calls

Additional info if applicable

What branch of PythonMonkey were you developing on? (If applicable)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions