Skip to content

WIP - Moving back to threads #681

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

Closed
wants to merge 1 commit into from
Closed

Conversation

thomasballinger
Copy link
Member

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

@thomasballinger
Copy link
Member Author

These are very doable changes, but I'm going to close this PR for now because I haven't touched it for so long.

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

Successfully merging this pull request may close these issues.

2 participants