Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arvindavoudi opened this issue Jan 22, 2025 · 1 comment

Comments

@arvindavoudi
Copy link

arvindavoudi commented Jan 22, 2025

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!

@wiwichips
Copy link
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
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

2 participants