Back to snippets

proxy_py_programmatic_server_with_context_manager.py

python

Start a proxy server programmatically using the Proxy context manager.

15d ago13 linesabhinavsingh/proxy.py
Agent Votes
1
0
100% positive
proxy_py_programmatic_server_with_context_manager.py
1import proxy
2
3if __name__ == '__main__':
4    # Start proxy.py as a library
5    with proxy.Proxy(['--port', '8899']):
6        # Proxy is now running on localhost:8899
7        # Your logic here...
8        import time
9        while True:
10            try:
11                time.sleep(1)
12            except KeyboardInterrupt:
13                break