-
-
Notifications
You must be signed in to change notification settings - Fork 616
[HELP] Unable to share state between the main app and a plugin #1468
Unanswered
ProtocolNebula
asked this question in
Q&A
-
Hi,
I'm trying to do a plugin to do a "rotate proxy", but the next IP must be rotated by the main app, not the plugin itself.
I have the following code:
import proxy from proxy.http.proxy import HttpProxyBasePlugin class CustomProxyRedirection(HttpProxyBasePlugin): currentProxy = { "address": "0.0.0.0" } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def before_upstream_connection(self, request): print(f'Proxy host: {CustomProxyRedirection.currentProxy['address']}') proxy_host, proxy_port = CustomProxyRedirection.currentProxy['address'].split(':') # Set the proxy for the request request.host = proxy_host request.port = int(proxy_port) return request class ProxyManager: proxy = None def __init__(self): self.proxy = proxy.Proxy(port=8899, plugins=[ CustomProxyRedirection, ]) def nextProxy(self): CustomProxyRedirection.currentProxy['address'] ="154.94.5.241:7001" # EXTREME CASE WHERE I INSTANTIATE THE WHOLE PROXY AGAIN self.proxy = proxy.Proxy(port=8899, plugins=[ CustomProxyRedirection, ]) # Example to run the proxy def main(): proxyManager = ProxyManager() proxyManager.nextProxy() with proxyManager.proxy as p: logger.info('Application started') proxy.sleep_loop() if __name__ == '__main__': main()
I've tried different solutions, even I tried to understand how to use the multiprocess manager
, but I found no way to do it.
Someone can please help me with an example or an explanation of how can I do it? (I assume that I have to spawn by myself the proxy, but I'm too new to python and found no clues/information of how to manage this case).
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
- If multiprocessing state sharing feels tricky, simply use an external storage like file on Disk, Sqlite, Memcache, Redis etc for sharing states.
- You may use Python's inbuilt multiprocessing shared variables for the same too
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment