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

blocking call (Home assistant) #612

Open
stefanuytterhoeven opened this issue Jul 1, 2024 · 12 comments
Open

blocking call (Home assistant) #612

stefanuytterhoeven opened this issue Jul 1, 2024 · 12 comments

Comments

@stefanuytterhoeven
Copy link

I got this error:
Logger: homeassistant.util.loop
Source: util/loop.py:84
First appearance: 08:20:01 (1 gebeurtenissen)
Last logged: 08:20:01

Detected blocking call to open inside the event loop by custom integration 'pyscript' at custom_components/pyscript/trigger.py, line 626: time_sun = location.sunset(dt.date(year, month, day)) (offender: /usr/local/lib/python3.12/site-packages/pytz/init.py, line 108: return open(filename, 'rb')), please create a bug report at https://github.com/custom-components/pyscript/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/config/custom_components/pyscript/function.py", line 448, in run_coro result = await coro File "/config/custom_components/pyscript/trigger.py", line 1010, in trigger_watch time_next = TrigTime.timer_trigger_next(self.time_trigger, now, startup_time) File "/config/custom_components/pyscript/trigger.py", line 727, in timer_trigger_next this_t = cls.parse_date_time(match1[1].strip(), 0, now, startup_time) File "/config/custom_components/pyscript/trigger.py", line 626, in parse_date_time time_sun = location.sunset(dt.date(year, month, day))

Can you solve this. (HAOS 12.4)

@jkfranks9
Copy link

I'm seeing similar errors, running HA 2024.7.0.

2024-07-04 09:57:49.233 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to walk with args (b'/config/pyscript',) inside the event loop by custom integration 'pyscript' at custom_components/pyscript/__init__.py, line 335: observer.start() (offender: /usr/local/lib/python3.12/site-packages/watchdog/observers/inotify_c.py, line 394: for root, dirnames, _ in os.walk(path):), please create a bug report at https://github.com/custom-components/pyscript/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#walk
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/config/custom_components/pyscript/__init__.py", line 335, in hass_started
    observer.start()

2024-07-04 09:57:49.257 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to scandir with args (b'/config/pyscript',) inside the event loop by custom integration 'pyscript' at custom_components/pyscript/__init__.py, line 335: observer.start() (offender: <frozen os>, line 366: ?), please create a bug report at https://github.com/custom-components/pyscript/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#scandir
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/config/custom_components/pyscript/__init__.py", line 335, in hass_started
    observer.start()

@amckenny
Copy link
Contributor

amckenny commented Jul 7, 2024

I obtained the same (verbatim as far as I can tell) warnings as @jkfranks9 on:
Core: 2024.7.1
Supervisor: 2024.06.2
Operating System: 12.4
Frontend: 20240705.0

Edit:
Looks like this may be similar to #608 and #609

@craigbarratt
Copy link
Member

craigbarratt commented Jul 8, 2024

The sunrise/sunset issue should be fixed by @IgnusG's PR #610, which has been applied. It would be great if someone could test github main to confirm the fix.

@jkfranks9
Copy link

Not a github expert, so I may not have done this correctly. But I copied the 2 files in #610 (manifest.json, trigger.py ... ignoring test stuff). I rebooted and see the same problem noted in this issue. If by "sunrise/sunset issue" you mean #608, I never saw that problem.

@IgnusG
Copy link
Contributor

IgnusG commented Jul 9, 2024

If by "sunrise/sunset issue" you mean #608, I never saw that problem.

@jkfranks9 I think #608 only occurs if you use something like @time_trigger('once(sunrise)') somewhere in your pyscript files. The original issue description of #612 refers to the same issue as #609 and #608.

The issue you saw in #612 (comment) occurs in a different situation (not caused by time based triggers like the sunrise/sunset issue). I did not fix that in my PR - it should however be fixed by @craigbarratt in the latest master branch so you can try that one out maybe 👀

These blocking call warnings can occur from anywhere within homeassistant integrations (they are not exclusive to pyscript) and they can be caused by different things (even by different functionalities pyscript offers).
Home assistant tries to help here by identifying them as they can result in poor user experience if not fixed - but the way to fix them can be different depending on where they occur

@jkfranks9
Copy link

Thanks, so I believe I should open a new issue for the problem I mentioned in comment 2. Will do that when I get a chance.

@IgnusG
Copy link
Contributor

IgnusG commented Jul 9, 2024

Thanks, so I believe I should open a new issue for the problem I mentioned in comment 2. Will do that when I get a chance.

Please first try to deploy master to see if the problem still occurs, otherwise yes it would be best to open a new GitHub issue for it 🙏

If you use sunrise/sunset and you don't see any warnings for those, this issue as well as #608 can be closed

@jkfranks9
Copy link

I pulled in the master branch, and I no longer see the blocking problem. Thanks.

@IgnusG
Copy link
Contributor

IgnusG commented Jul 9, 2024

I pulled in the master branch, and I no longer see the blocking problem. Thanks.

CC @craigbarratt

@Just-Zuul
Copy link

@craigbarratt

include: Detected blocking call #619

@demey
Copy link

demey commented Jul 25, 2024

Core 2024.7.3
Supervisor 2024.06.2
Operating System 12.4

The same messages related to os.walk() and os.scandir() appear even 'config/pyscript' folder is empty.

@IgnusG
Copy link
Contributor

IgnusG commented Jul 25, 2024

Hey @craigbarratt 👋 Could you create a new release for the latest changes?

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

7 participants