镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

PythonMonkey cannot find a running Python event-loop to make asynchronous calls. #469

Open

Description

@arvindavoudi

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

MacOS 15.1

Python version (python --version)

3.11.9

PythonMonkey version (pip show pythonmonkey)

1.1.0

Bug Description

Hi,
I attempted to load the lightstreamer-client JavaScript library in Python using PythonMonkey as shown below:

import pythonmonkey as pm
lsc = pm.require("lightstreamer-client")

However, I encountered the following error:

Traceback (most recent call last):
  File ".../test.py", line 4, in <module>
    lsc = pm.require("lightstreamer-client")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pythonmonkey/require.py", line 431, in require
    return createRequire(filename)(moduleIdentifier)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: PythonMonkey cannot find a running Python event-loop to make asynchronous calls.

Could you provide guidance on how to resolve this issue?
Thank you!

Activity

  1. wiwichips commented on Mar 25, 2025

    @wiwichips
    Collaborator

    Hi @arvindavoudi , this happens when the JavaScript code requires an event loop (for example: code that uses setTimeout)

    You need to evaluate the JS code in a Python event loop. Refer to the asyncio standard library: https://docs.python.org/3/library/asyncio.html

    Not sure if this will work in your use case, but try running:

    import asyncio
    import pythonmonkey as pm
    
    async def pm_async_wrapper():
      lsc = pm.require("lightstreamer-client")
    
    asyncio.run(pm_async_wrapper())
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

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions