Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork620
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hello ! I have my main file : and my plugin I want my plugin edit a variable which will allow to the main process to shutdown proxy. I already read thishttps://github.com/abhinavsingh/proxy.py/blob/develop/tutorial/eventing.ipynb but i don't understand how i can make this. Please help by directing me to achieve this. |
BetaWas this translation helpful?Give feedback.
All reactions
Initially, I opted for this solution:https://docs.python.org/3/library/multiprocessing.shared_memory.html.
This allowed me to share my variables directly from the buffer.
However, I became interested in your solution, which gave me the following result.
app.py
defstart_proxy(self,p:ProxyModel):p.started=Truewithproxy.Proxy(input_args=self.create_input_args(p))asp_process:whileproxy_service.proxies[p.id]andproxy_service.proxies[p.id].started:self.update_proxy(p,p_process.event_manager.queue.queue)self.stop_proxy(p)defupdate_proxy(self,p:ProxyModel,queue:Queue):try:update=queue.get(timeout=1)ifupdate["…
Replies: 2 comments 2 replies
-
I think for this purpose you can just use Purpose of eventing is mostly to communicate information between processes rather than sharing a global variable. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Initially, I opted for this solution:https://docs.python.org/3/library/multiprocessing.shared_memory.html. However, I became interested in your solution, which gave me the following result. app.py defstart_proxy(self,p:ProxyModel):p.started=Truewithproxy.Proxy(input_args=self.create_input_args(p))asp_process:whileproxy_service.proxies[p.id]andproxy_service.proxies[p.id].started:self.update_proxy(p,p_process.event_manager.queue.queue)self.stop_proxy(p)defupdate_proxy(self,p:ProxyModel,queue:Queue):try:update=queue.get(timeout=1)ifupdate["event_name"]==eventNames.TRAFFIC_IN:p.traffic_in_current+=update["chunk"]exceptEmpty:pass plugin.py defhandle_upstream_chunk(self,chunk):self.event_queue.queue.put({"event_name":eventNames.TRAFFIC_IN,"chunk":len(chunk)})returnchunk This solution is more concise and does not require managing variable synchronization; it is simply better! |
BetaWas this translation helpful?Give feedback.
All reactions
-
Totally agreed. Myself I would have just used primitives provided by Overall your implementation looks good to me. Ideally, developers should see |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
One problem I see with build in eventing mechanism is, in-ability to provide/declare custom event names, which currently is a hardcoded enum IIRC. We'll try to (somehow) address this limitation in future releases. Otherwise, currently, you must have been forced to change a piece of code in the core to add |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1