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

There is no current event loop in thread 'ScriptRunner.scriptThread' Error #101

Open
jrriehl opened this issue Jun 5, 2023 · 4 comments

Comments

@jrriehl
Copy link
Contributor

jrriehl commented Jun 5, 2023

Moved from here: fetchai/cosmpy#360

i think asyncio.get_event_loop() method works within uagents module ?
and how to call asyncio.get_event_loop() function in uagents module?

class ASGIServer:
def init(
self,
port: int,
loop: asyncio.AbstractEventLoop,
queries: Dict[str, asyncio.Future],
logger: Optional[Logger] = None,
):
self._port = int(port)
self._loop = loop
self._queries = queries
self._logger = logger or get_logger("server")
self._server = None
there is no get method so sadly frowning
because of that, it conflicts to streamlit module
and i get the following error:

File "C:\Users\selcu\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.

@jrriehl
Copy link
Contributor Author

jrriehl commented Jun 5, 2023

What command are you running that results in this error?

Normally, when you run agent.run(), an event loop will be started if there is none currently running.

But in general, you should be able to use asyncio.get_event_loop() to get an event loop independent of any module.

@selcuktopal80
Copy link

I work on the script: (it is recomended by fetchai in the link https://docs.fetch.ai/uAgents/simple-interaction/#add-a-second-agent)

lets say it agents.py. in the terminal, when I run python agents.py it works well.

My problem is the usage of this code in a Python framework (web frameworks). In any framework, when a state change is a must, I get the error "get_event_loop raise RuntimeError('There is no current event loop in thread %r.' RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'". So I thouhgt that ı need to call asyncio.get_event_loop(). I try to visulate ctx.logger.info in a print method (not a console (window) log or any console print (terminal) method). when i tried to use your script by modifing the framework, it gave the error above.

from uagents import Agent, Context, Bureau

alice = Agent(name="alice", seed="alice recovery phrase")
bob = Agent(name="bob", seed="bob recovery phrase")

@alice.on_interval(period=2.0)
async def say_hello(ctx: Context):
ctx.logger.info(f'Hello, my name is {ctx.name}')

@bob.on_interval(period=2.0)
async def say_hello(ctx: Context):
ctx.logger.info(f'Hello, my name is {ctx.name}')

bureau = Bureau()
bureau.add(alice)
bureau.add(bob)

if name == "main":
bureau.run()

@jrriehl
Copy link
Contributor Author

jrriehl commented Jun 5, 2023

Thanks for the extra info! It's not clear to me which web framework you are using, but for some web frameworks it helps to install nest_asycnio and run the following at the top of your script:

import nest_asyncio
nest_asyncio.apply()

So that might be worth a try. If that doesn't work, can you say which particular web framework you are using?

@selcuktopal80
Copy link

selcuktopal80 commented Jun 6, 2023

Thanks for the extra info! It's not clear to me which web framework you are using, but for some web frameworks it helps to install nest_asycnio and run the following at the top of your script:

import nest_asyncio
nest_asyncio.apply()

So that might be worth a try. If that doesn't work, can you say which particular web framework you are using?

I am working on streamlit dapp, it has own asyncio function inside, so uagents module and streamlit are incompatible sadly.

your recommendation did not solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants