-
Notifications
You must be signed in to change notification settings - Fork 63
Description
Calling exit() in the beginning of a .py file causes whole Home Assistant to crash, making it difficult to recover (it is a race between you trying to delete the problematic file and pyscript starting to run)
Simplified test
exit()Repro steps
- Create a backup of your Home Assistant! You might be unable to recover it otherwise!
- Add the abovementioned simplified test to ~/config/pyscript in your Home Assistant.
- Let it run
- Observe the logs (Settings -> System -> Logs)
Actual result
The exit() command is not executed inside your file.py, but (apparently) on the system-level:
2026-02-01 17:26:27.864 INFO (MainThread) [homeassistant.setup] Setting up pyscript
2026-02-01 17:26:27.865 INFO (MainThread) [homeassistant.setup] Setup of domain pyscript took 0.00 seconds
2026-02-01 17:26:27.869 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry pyscript for pyscript
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 762, in __async_setup_with_context
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/pyscript/__init__.py", line 286, in async_setup_entry
await load_scripts(hass, config_entry.data, global_ctx_only=global_ctx_only)
File "/config/custom_components/pyscript/__init__.py", line 727, in load_scripts
await GlobalContextMgr.load_file(
global_ctx, src_info.file_path, source=src_info.source, reload=reload
)
File "/config/custom_components/pyscript/global_ctx.py", line 338, in load_file
await ast_ctx.eval()
File "/config/custom_components/pyscript/eval.py", line 2334, in eval
val = await self.aeval(self.ast)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/pyscript/eval.py", line 946, in aeval
val = await getattr(self, name, self.ast_not_implemented)(arg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/pyscript/eval.py", line 963, in ast_module
val = await self.aeval(arg1)
^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/pyscript/eval.py", line 946, in aeval
val = await getattr(self, name, self.ast_not_implemented)(arg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/pyscript/eval.py", line 1393, in ast_expr
return await self.aeval(arg.value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/pyscript/eval.py", line 946, in aeval
val = await getattr(self, name, self.ast_not_implemented)(arg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/pyscript/eval.py", line 1967, in ast_call
return await self.call_func(func, func_name, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/pyscript/eval.py", line 2018, in call_func
return func(*args, **kwargs)
File "<frozen _sitebuiltins>", line 26, in __call__
SystemExit: NoneAfter this error is logged, Home Assistant stops responding.
Home Assistant can only be restarted as a whole container (through the parent machine). However, as soon as it starts up and loads pyscript, it will crash again.
Expected result
Just the file.py should finish its execution (exit). This should not affect the rest of the Home Assistant.
How to solve (as user)
As soon as Home Assistant starts up, delete/comment the problematic file.py (through VS Code, Terminal, ssh etc.). You need to be quick – if pyscript is faster than you, it will crash again.
Alternatively, you could try to disable/deactivate the pyscript integration.
Version
Pyscript: Python Scripting for Home Assistant 1.7.0
Installation method Home Assistant OS
Core 2026.1.3
Supervisor 2026.01.1
Operating System 17.0
Frontend 20260107.2
Additional info
This happened to me when I put exit() as the first line of a larger .py file. If needed, I can provide the whole file. It is just my assumption that the provided simplified test will cause the same issue – I haven't tried it again deliberately, for obvious reasons.