-
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 this https://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. |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
-
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 def start_proxy(self, p: ProxyModel):
p.started = True
with proxy.Proxy(input_args=self.create_input_args(p)) as p_process:
while proxy_service.proxies[p.id] and proxy_service.proxies[p.id].started:
self.update_proxy(p, p_process.event_manager.queue.queue)
self.stop_proxy(p)
def update_proxy(self, p: ProxyModel, queue: Queue):
try:
update = queue.get(timeout=1)
if update["event_name"] == eventNames.TRAFFIC_IN:
p.traffic_in_current += update["chunk"]
except Empty:
pass plugin.py def handle_upstream_chunk(self, chunk):
self.event_queue.queue.put({"event_name": eventNames.TRAFFIC_IN, "chunk": len(chunk)})
return chunk This solution is more concise and does not require managing variable synchronization; it is simply better! |
Beta Was this translation helpful? Give feedback.
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