MCPcopy
hub / github.com/bugy/script-server / run_sync

Function run_sync

src/utils/tornado_utils.py:153–176  ·  view source on GitHub ↗
(func)

Source from the content-addressed store, hash-verified

151
152
153def run_sync(func):
154 global separate_io_loop
155
156 if separate_io_loop is None:
157 with io_loop_lock:
158 if separate_io_loop is None:
159 io_loop_future = Future()
160
161 def run_new_ioloop():
162 try:
163 io_loop = asyncio.new_event_loop()
164 io_loop_future.set_result(io_loop)
165 io_loop.run_forever()
166 except Exception as e:
167 io_loop_future.set_exception(e)
168
169 # We need to run it in another thread because ioloop.current.run_sync starts/stops the current ioloop,
170 # which is not acceptable
171 thread = threading.Thread(target=run_new_ioloop, daemon=True)
172 thread.start()
173 separate_io_loop = io_loop_future.result()
174
175 future = asyncio.run_coroutine_threadsafe(func, separate_io_loop)
176 return future.result()

Callers

nothing calls this directly

Calls 1

startMethod · 0.45

Tested by

no test coverage detected