question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Detected I/O inside the event loop

See original GitHub issue

Hi What about this warning in the log? It’s my fault?

WARNING (MainThread) [homeassistant.util.async_] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for pyscript doing I/O at custom_components/pyscript/eval.py, line 1143: return func(*args, **kwargs) Thank you

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
craigbarrattcommented, Sep 13, 2020

One more comment before I close this issue. If you need to do I/O from pyscript, the best solution is to find a package that is native async-based and use that. For example, instead of requests or urllib.request.urlopen, consider using aiohttp instead.

Looking at the client examples in aiohttp, you can fetch a URL with (there’s no need to include the await keyword; it is optional in pyscript):

import aiohttp

async with aiohttp.ClientSession() as session:
    async with session.get('https://raw.githubusercontent.com/custom-components/pyscript/master/README.md') as resp:
        print(resp.status)
        print(resp.text())

This is supported in the master code, but not the current release 0.21. So if you want to use async with you’ll need to run the master version instead of 0.21.

0reactions
craigbarrattcommented, Sep 8, 2020

I pushed a change 5908b4b that adds a new function, task.executor(). You can use that to call functions in packages that do I/O. task.executor() calls the function using run_in_executor(), which runs the function in a thread instead of the event loop.

Its arguments are the function to call, and the arguments that should be passed to that function. So instead of doing something like:

import requests

resp = requests.get('https://raw.githubusercontent.com/custom-components/pyscript/master/README.md')

you should do this instead:

import requests

resp = task.executor(requests.get, 'https://raw.githubusercontent.com/custom-components/pyscript/master/README.md')

There is no need to use task.executor() when the following code uses resp.text or resp.status_code since those don’t do I/O.

This is an experimental feature at this point. Please tell me if it fixes the warning you saw.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detected I/O inside the event loop · Issue #232 - GitHub
In HomeAssistant 0.109.0b0 I have the folowing warning: Log Details (WARNING) Logger: homeassistant.util.async_. Source: util/async_.py:120
Read more >
Detected i/o inside the event loop - Home Assistant Community
I'm using the abandoned gtask custom component since there's no todo lists integration. I'm having the following warning making it quite ...
Read more >
The event loop - JavaScript - MDN Web Docs - Mozilla
JavaScript has a runtime model based on an event loop, which is responsible for executing the code, collecting and processing events, ...
Read more >
Event Loop — Python 3.11.1 documentation
Event loops run asynchronous tasks and callbacks, perform network IO operations, and run subprocesses. Application developers should typically use the high- ...
Read more >
Detect an idle asyncio event loop - Stack Overflow
Say that my execution path branches in some complex way, say, using asyncio.gather(), but I know that each branch eventually awaits some idle ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found