MCPcopy Create free account
hub / github.com/apify/impit / start_proxy_server

Function start_proxy_server

impit-python/test/setup_proxy.py:9–45  ·  view source on GitHub ↗
(port: int = 3002)

Source from the content-addressed store, hash-verified

7
8
9def start_proxy_server(port: int = 3002) -> typing.Callable[[], None]:
10 def run_proxy_server(stop_event: threading.Event) -> None:
11 server = pproxy.Server(f'http://0.0.0.0:{port}')
12 args = {'rserver': [], 'verbose': print}
13
14 loop = asyncio.new_event_loop()
15 asyncio.set_event_loop(loop)
16 handler = loop.run_until_complete(server.start_server(args))
17
18 try:
19 while not stop_event.is_set():
20 loop.run_until_complete(asyncio.sleep(0.1))
21 except KeyboardInterrupt:
22 print('exit!')
23
24 handler.close()
25 loop.run_until_complete(handler.wait_closed())
26 loop.run_until_complete(loop.shutdown_asyncgens())
27 loop.close()
28
29 # Event to signal the proxy server to stop
30 stop_event = threading.Event()
31
32 # Start the proxy server in a separate thread
33 proxy_thread = threading.Thread(target=run_proxy_server, args=(stop_event,), daemon=True)
34 proxy_thread.start()
35
36 # wait a moment for the server to start
37
38 time.sleep(1)
39
40 # Return a function to stop the server
41 def stop_server() -> None:
42 stop_event.set()
43 proxy_thread.join(1)
44
45 return stop_server

Callers 3

test_proxyMethod · 0.85
test_proxyMethod · 0.85
test_proxyMethod · 0.85

Calls

no outgoing calls

Tested by 3

test_proxyMethod · 0.68
test_proxyMethod · 0.68
test_proxyMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…