Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
trying to finish
  • Loading branch information
thomasballinger committed Oct 7, 2021
commit 25766566581adc9013ddb6ecaf5f68ecb39f3042
16 changes: 8 additions & 8 deletions bpython/curtsiesfrontend/coderunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class CodeRunner:
"""Runs user code in an interpreter.

Running code requests a refresh by calling
request_from_main_context(force_refresh=True), which
request_from_main_thread(force_refresh=True), which
suspends execution of the code by blocking on a queue
that the main thread was blocked on.

After load_code() is called with the source code to be run,
the run_code() method should be called to start running the code.
The running code may request screen refreshes and user input
by calling request_from_main_context.
by calling request_from_main_thread.
When this are called, the running source code cedes
control, and the current run_code() method call returns.

Expand Down Expand Up @@ -98,7 +98,7 @@ def __init__(self, interp=None, request_refresh=lambda: None):
# waiting for response from main thread
self.code_is_waiting = False
# sigint happened while in main thread
self.sigint_happened_in_main_context = False # TODO rename context to thread
self.sigint_happened_in_main_thread = False # TODO rename context to thread
self.orig_sigint_handler = None

@property
Expand Down Expand Up @@ -142,8 +142,8 @@ def run_code(self, for_code=None):
self.code_is_waiting = False
if is_main_thread():
signal.signal(signal.SIGINT, self.sigint_handler)
if self.sigint_happened_in_main_context:
self.sigint_happened_in_main_context = False
if self.sigint_happened_in_main_thread:
self.sigint_happened_in_main_thread = False
self.responses_for_code_thread.put(SigintHappened)
else:
self.responses_for_code_thread.put(for_code)
Expand Down Expand Up @@ -180,7 +180,7 @@ def sigint_handler(self, *args):
"sigint while fulfilling code request sigint handler "
"running!"
)
self.sigint_happened_in_main_context = True
self.sigint_happened_in_main_thread = True

def _blocking_run_code(self):
try:
Expand All @@ -192,7 +192,7 @@ def _blocking_run_code(self):
if unfinished
else Done())

def request_from_main_context(self, force_refresh=False):
def request_from_main_thread(self, force_refresh=False):
"""Return the argument passed in to .run_code(for_code)

Nothing means calls to run_code must be... ???
Expand Down Expand Up @@ -223,7 +223,7 @@ def __init__(self, coderunner, on_write, real_fileobj):

def write(self, s, *args, **kwargs):
self.on_write(s, *args, **kwargs)
return self.coderunner.request_from_main_context(force_refresh=True)
return self.coderunner.request_from_main_thread(force_refresh=True)

# Some applications which use curses require that sys.stdout
# have a method called fileno. One example is pwntools. This
Expand Down
5 changes: 3 additions & 2 deletions bpython/curtsiesfrontend/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ def process_event(self, e):
assert self.in_prompt or self.in_confirm or self.waiting_for_refresh
if isinstance(e, RefreshRequestEvent):
self.waiting_for_refresh = False
self.request_context.switch()
self.request_or_notify_queue.put(None)
self.response_queue.get()
elif isinstance(e, events.PasteEvent):
for ee in e.events:
# strip control seq
self.add_normal_character(ee if len(ee) == 1 else ee[-1])
elif e == "<ESC>" or isinstance(e, events.SigIntEvent):
self.request_context.switch(False)
self.request_queue.put(False)
self.escape()
elif e in edit_keys:
self.cursor_offset_in_line, self._current_line = edit_keys[e](
Expand Down
4 changes: 2 additions & 2 deletions bpython/curtsiesfrontend/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def process_event(self, e):
self.cursor_offset, self.current_line
)
elif isinstance(e, events.SigIntEvent):
self.coderunner.sigint_happened_in_main_context = True
self.coderunner.sigint_happened_in_main_thread = True
self.has_focus = False
self.current_line = ""
self.cursor_offset = 0
Expand Down Expand Up @@ -164,7 +164,7 @@ def add_input_character(self, e):
def readline(self):
self.has_focus = True
self.repl.send_to_stdin(self.current_line)
value = self.coderunner.request_from_main_context()
value = self.coderunner.request_from_main_thread()
self.readline_results.append(value)
return value

Expand Down