reloadium
reloadium copied to clipboard
not reloading on `input()`
Describe the bug
Using a simple script that accepts user input via input()
in a loop, the code changes are not reloaded as would be expected.
To Reproduce
- write a script with:
s = ''
while s != 'exit':
s = input('> ')
print(f'you entered: {s}')
- run script with reloadium
- enter some text on input, e.g. "hi" which will produce the expected output "you entered: hi"
- change line 4 in the script to
print(f'USER entered: {s}')
- enter some text on input, e.g. "hi"
Expected behavior
The code should be reloaded during execution and the output should be "USER entered: hi". Instead, the output is still "you entered: hi". Subsequent inputs produce the same output (i.e. no change is applied). See this log:
/usr/bin/python3.10 -m reloadium run <CENSORED>/reloadiumtest/reloadiumtest.py
■■■■■■■■■■■■■■■
Reloadium 0.9.0
■■■■■■■■■■■■■■■
If you like this project consider becoming a sponsor or giving a star at https://github.com/reloadware/reloadium
>
Loaded 1 watched modules so far from paths:
- <CENSORED>/reloadiumtest/**/*.py
hi
you entered: hi
> Update Module: __main__
hi again
you entered: hi again
Desktop (please complete the following information):
- OS: Linux
- OS version: Ubuntu 22.04
- Reloadium package version: 0.9.0
- PyCharm plugin version: 0.8.3
- Editor: PyCharm
- Run mode: Run
Additional context
Also tried to disable reloadium cache, but problem remains.
Actually it also doesn't work when running a loop with sleep()
like this although I get Update Module: __main__
after saving a change:
from time import sleep
while True:
sleep(1)
print('test')
And in Debug it only works when the debugger stops on a breakpoint, then I change the line, then I resume.
The reason why this is not working is because you are changing code that is already being executed on the call stack. In order for this to work the call stack frame has to be restarted and that is only possible during debugging.
I'll keep this issue open until I add a warning message or document this behavior better.
Empty Update Module: __main__
message is also quite misleading here.