MCPcopy
hub / github.com/Kanaries/pygwalker / _start_server

Function _start_server

pygwalker/api/webserver.py:123–154  ·  view source on GitHub ↗

Start a server with walker

(
    walker: PygWalker,
    port: Optional[int],
    *,
    auto_open: bool,
    auto_shutdown: bool,
)

Source from the content-addressed store, hash-verified

121
122
123def _start_server(
124 walker: PygWalker,
125 port: Optional[int],
126 *,
127 auto_open: bool,
128 auto_shutdown: bool,
129):
130 """Start a server with walker"""
131 state = _GlobalState(auto_shutdown=auto_shutdown)
132 walker._init_callback(BaseCommunication(str(walker.gid)))
133
134 handler = _create_handler_with_walker(walker, state)
135 if port is None:
136 port = find_free_port()
137 address = f"http://localhost:{port}"
138
139 def _listen_shutdown():
140 while 1:
141 time.sleep(1)
142 if time.time() - state.last_health_time > _MAX_HEALTH_TIMEOUT_SECONDS:
143 httpd.shutdown()
144 break
145
146 try:
147 with CustomTCPServer(("127.0.0.1", port), handler) as httpd:
148 if auto_open:
149 threading.Thread(target=_open_browser, args=(address,)).start()
150 if auto_shutdown:
151 threading.Thread(target=_listen_shutdown).start()
152 httpd.serve_forever()
153 except KeyboardInterrupt:
154 pass
155
156
157def walk(

Callers 3

walkFunction · 0.85
renderFunction · 0.85
tableFunction · 0.85

Calls 6

BaseCommunicationClass · 0.90
find_free_portFunction · 0.90
_GlobalStateClass · 0.85
CustomTCPServerClass · 0.85
_init_callbackMethod · 0.80

Tested by

no test coverage detected