-
Notifications
You must be signed in to change notification settings - Fork 57
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
Minimal changes to allow manual re-initialization of NodeJS process #131
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
45ce76f
Minimal changes to allow manual init/terminate
Tales-Carvalho 2bea51e
Init EventLoop queue in constructor
Tales-Carvalho 3c4e5c2
Move other EventLoop and EventExecutorThread variables to constructor
Tales-Carvalho a06ee46
Set global references in init()
Tales-Carvalho 972c781
Restore error checking and manage sendQ
Tales-Carvalho e2a0780
Adds docs about controlling NodeJS process in python
Tales-Carvalho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,12 @@ def wait(self, sec): | |
|
||
|
||
class EventExecutorThread(threading.Thread): | ||
running = True | ||
jobs = Queue() | ||
doing = [] | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.running = True | ||
self.jobs = Queue() | ||
self.doing = [] | ||
self.daemon = True | ||
|
||
def add_job(self, request_id, cb_id, job, args): | ||
|
@@ -44,32 +44,33 @@ def run(self): | |
# JS and Python happens through this event loop. Because of Python's "Global Interperter Lock" | ||
# only one thread can run Python at a time, so no race conditions to worry about. | ||
class EventLoop: | ||
active = True | ||
queue = Queue() | ||
freeable = [] | ||
|
||
callbackExecutor = EventExecutorThread() | ||
def __init__(self): | ||
connection.start() | ||
|
||
# This contains a map of active callbacks that we're tracking. | ||
# As it's a WeakRef dict, we can add stuff here without blocking GC. | ||
# Once this list is empty (and a CB has been GC'ed) we can exit. | ||
# Looks like someone else had the same idea :) | ||
# https://stackoverflow.com/questions/21826700/using-python-weakset-to-enable-a-callback-functionality | ||
callbacks = WeakValueDictionary() | ||
self.active = True | ||
self.freeable = [] | ||
self.queue = Queue() | ||
|
||
# The threads created managed by this event loop. | ||
threads = [] | ||
# This contains a map of active callbacks that we're tracking. | ||
# As it's a WeakRef dict, we can add stuff here without blocking GC. | ||
# Once this list is empty (and a CB has been GC'ed) we can exit. | ||
# Looks like someone else had the same idea :) | ||
# https://stackoverflow.com/questions/21826700/using-python-weakset-to-enable-a-callback-functionality | ||
self.callbacks = WeakValueDictionary() | ||
|
||
outbound = [] | ||
# The threads created managed by this event loop. | ||
self.threads = [] | ||
|
||
# After a socket request is made, it's ID is pushed to self.requests. Then, after a response | ||
# is recieved it's removed from requests and put into responses, where it should be deleted | ||
# by the consumer. | ||
requests = {} # Map of requestID -> threading.Lock | ||
responses = {} # Map of requestID -> response payload | ||
self.outbound = [] | ||
|
||
def __init__(self): | ||
connection.start() | ||
# After a socket request is made, it's ID is pushed to self.requests. Then, after a response | ||
# is recieved it's removed from requests and put into responses, where it should be deleted | ||
# by the consumer. | ||
self.requests = {} # Map of requestID -> threading.Lock | ||
self.responses = {} # Map of requestID -> response payload | ||
|
||
self.callbackExecutor = EventExecutorThread() | ||
self.callbackExecutor.start() | ||
self.pyi = pyi.PyInterface(self, config.executor) | ||
|
||
|
@@ -163,7 +164,7 @@ def loop(self): | |
self.threads = [x for x in self.threads if x[2].is_alive()] | ||
|
||
if len(self.freeable) > 40: | ||
self.queue_payload({"r": r, "action": "free", "ffid": "", "args": self.freeable}) | ||
self.queue_payload({"r": 0, "action": "free", "ffid": "", "args": self.freeable}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About this change: currently this does not work at all because |
||
self.freeable = [] | ||
|
||
# Read the inbound data and route it to correct handler | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a note for this and the other new API method to the docs along with an explanation or how to use?