X Tutup
The Wayback Machine - https://web.archive.org/web/20200905014525/https://github.com/bpython/bpython/pull/681
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

WIP - Moving back to threads #681

Open
wants to merge 1 commit into
base: master
from
Open

WIP - Moving back to threads #681

wants to merge 1 commit into from

Conversation

@thomasballinger
Copy link
Member

thomasballinger commented Apr 22, 2017

First draft of moving back to threads from greenlets. So far this is just the reverse of 2e54cbb

The real work here will be making sure I understand threading model in this code I wrote 3.5 years ago.

Todo:

  • fix undo ("Main thread blocked..." exception)
  • better document threads and how they interact
  • detect currently running threads and prevent undo

Latency doesn't seem much worse: as measured by

def test():
    t0 = time.time()
    for i in range(1000):
        print i
    print time.time() - t0

I get 15.7 for greenlets (the current version), 16.4 for threads

@@ -95,60 +93,63 @@ def __init__(self, interp=None, request_refresh=lambda: None):
"""
self.interp = interp or code.InteractiveInterpreter()
self.source = None
self.main_context = greenlet.getcurrent()
self.code_context = None
self.code_thread = None

This comment has been minimized.

@sebastinas

sebastinas Apr 23, 2017

Contributor

The intention of 3057732 and 2b8c30b was to use generic names so we do not have to rename them every time we change the implementation.

self.request_refresh = request_refresh
# waiting for response from main thread
self.code_is_waiting = False
# sigint happened while in main thread
self.sigint_happened_in_main_context = False
self.sigint_happened_in_main_context = False # TODO rename context to thread

This comment has been minimized.

@sebastinas

sebastinas Apr 23, 2017

Contributor

See above.


def load_code(self, source):
"""Prep code to be run"""
assert self.source is None, "you shouldn't load code when some is " \
"already running"
self.source = source
self.code_context = None
self.code_thread = None

This comment has been minimized.

@sebastinas

sebastinas Apr 23, 2017

Contributor

See above. This is just noise.


def _unload_code(self):
"""Called when done running code"""
self.source = None
self.code_context = None
self.code_thread = None

This comment has been minimized.

@sebastinas

sebastinas Apr 23, 2017

Contributor

As above.

if source code is complete, returns "done"
if source code is incomplete, returns "unfinished"
"""
if self.code_context is None:
if self.code_thread is None:

This comment has been minimized.

@sebastinas

sebastinas Apr 23, 2017

Contributor

As above.

self.main_context = greenlet.getcurrent()
self.request_context = None
self.response_queue = queue.Queue()
self.request_or_notify_queue = queue.Queue()

This comment has been minimized.

@sebastinas

sebastinas Apr 23, 2017

Contributor

As above.

@thomasballinger thomasballinger force-pushed the back-to-threads branch from cd8febb to be211d8 Jul 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.
X Tutup