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

not reloading on input() #26

Open
internaut opened this issue Jul 20, 2022 · 2 comments
Open

not reloading on input() #26

internaut opened this issue Jul 20, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@internaut
Copy link

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

  1. write a script with:
s = ''
while s != 'exit':
    s = input('> ')
    print(f'you entered: {s}')
  1. run script with reloadium
  2. enter some text on input, e.g. "hi" which will produce the expected output "you entered: hi"
  3. change line 4 in the script to print(f'USER entered: {s}')
  4. 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.

@internaut
Copy link
Author

internaut commented Jul 20, 2022

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.

@dkrystki
Copy link
Contributor

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.

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

No branches or pull requests

2 participants