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

Handle concurrent inputs and computation gracefully #748

Open
BenWiederhake opened this issue Sep 11, 2018 · 1 comment
Open

Handle concurrent inputs and computation gracefully #748

BenWiederhake opened this issue Sep 11, 2018 · 1 comment

Comments

@BenWiederhake
Copy link

BenWiederhake commented Sep 11, 2018

Steps to reproduce: Make some keyboard inputs while bpython is executing some code.
Actual behavior: Crash, wth a nice error message
Expected behavior: Begin interpreting the key presses only after the code has finished executing. Or something.

Minimal reproducing example:

  • Start bpython
  • Define a function that takes some time to compute. The bug seems to depend on actual execution. time.sleep does not trigger the bug.
  • Call it normally, and immediately after pressing enter, press up, enter, enter.
  • After a few seconds, the expected output of the first invocation appears, and an empty prompt. From the CPU usage it seems that the second invocation is now running, but the invocation command does not appear on the console
  • After another few seconds, observe the error message.
$ bpython3
bpython version 0.16 on top of Python 3.5.3 /usr/bin/python3
>>> def foo():
...     return sum(x ** 0.5 - x ** 0.1 for x in range(10000000))
... 
>>> foo()
21036287013.578144
>>> 
Traceback (most recent call last):
  File "/usr/bin/bpython3", line 11, in <module>
    load_entry_point('bpython==0.16', 'console_scripts', 'bpython')()
  File "/usr/lib/python3/dist-packages/bpython/curtsies.py", line 190, in main
    exit_value = repl.mainloop()
  File "/usr/lib/python3/dist-packages/bpython/curtsies.py", line 125, in mainloop
    self.process_event_and_paint(e)
  File "/usr/lib/python3/dist-packages/bpython/curtsies.py", line 89, in process_event_and_paint
    self.process_event(e)
  File "/usr/lib/python3/dist-packages/bpython/curtsiesfrontend/repl.py", line 580, in process_event
    return self.process_control_event(e)
  File "/usr/lib/python3/dist-packages/bpython/curtsiesfrontend/repl.py", line 616, in process_control_event
    self.process_event(ee)
  File "/usr/lib/python3/dist-packages/bpython/curtsiesfrontend/repl.py", line 584, in process_event
    return self.process_key_event(e)
  File "/usr/lib/python3/dist-packages/bpython/curtsiesfrontend/repl.py", line 711, in process_key_event
    self.on_enter()
  File "/usr/lib/python3/dist-packages/bpython/curtsiesfrontend/repl.py", line 794, in on_enter
    self.push(self.current_line, insert_into_history=insert_into_history)
  File "/usr/lib/python3/dist-packages/bpython/curtsiesfrontend/repl.py", line 1057, in push
    self.coderunner.load_code(code_to_run)
  File "/usr/lib/python3/dist-packages/bpython/curtsiesfrontend/coderunner.py", line 113, in load_code
    assert self.source is None, "you shouldn't load code when some is " \
AssertionError: you shouldn't load code when some is already running
[$? = 1]

For comparison, the built-in interpreter of python3 seems to behave like I would have expected, that is: only begin interpretation of the "up arrow" key once the previous command has finished.

@thomasballinger
Copy link
Member

I can reproduce this, maybe some issue with the code running state machine or a race condition.

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

2 participants