mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-06-14 23:35:34 +08:00
added optional "asyncio_loop" argument to allow using existing event loop
Signed-off-by: bigcat88 <bigcat88@icloud.com>
This commit is contained in:
parent
7fa60b6fb8
commit
25a3c9e9c3
15
main.py
15
main.py
@ -228,10 +228,10 @@ def cleanup_temp():
|
|||||||
shutil.rmtree(temp_dir, ignore_errors=True)
|
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
def start_comfyui():
|
def start_comfyui(asyncio_loop=None):
|
||||||
"""
|
"""
|
||||||
Start the ComfyUI server. This function sets up the event loop, the server,
|
Starts the ComfyUI server using the provided asyncio event loop or creates a new one.
|
||||||
and runs until completion. It returns references that can be used elsewhere.
|
Returns the event loop, server instance, and a function to start the server asynchronously.
|
||||||
"""
|
"""
|
||||||
if args.temp_directory:
|
if args.temp_directory:
|
||||||
temp_dir = os.path.join(os.path.abspath(args.temp_directory), "temp")
|
temp_dir = os.path.join(os.path.abspath(args.temp_directory), "temp")
|
||||||
@ -246,8 +246,9 @@ def start_comfyui():
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
asyncio_loop = asyncio.new_event_loop()
|
if not asyncio_loop:
|
||||||
asyncio.set_event_loop(asyncio_loop)
|
asyncio_loop = asyncio.new_event_loop()
|
||||||
|
asyncio.set_event_loop(asyncio_loop)
|
||||||
prompt_server = server.PromptServer(asyncio_loop)
|
prompt_server = server.PromptServer(asyncio_loop)
|
||||||
q = execution.PromptQueue(prompt_server)
|
q = execution.PromptQueue(prompt_server)
|
||||||
|
|
||||||
@ -280,12 +281,12 @@ def start_comfyui():
|
|||||||
await run(prompt_server, address=args.listen, port=args.port, verbose=not args.dont_print_server, call_on_start=call_on_start)
|
await run(prompt_server, address=args.listen, port=args.port, verbose=not args.dont_print_server, call_on_start=call_on_start)
|
||||||
|
|
||||||
# Returning these so that other code can integrate with the ComfyUI loop and server
|
# Returning these so that other code can integrate with the ComfyUI loop and server
|
||||||
return asyncio_loop, start_all
|
return asyncio_loop, prompt_server, start_all
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Running directly, just start ComfyUI.
|
# Running directly, just start ComfyUI.
|
||||||
event_loop, start_all_func = start_comfyui()
|
event_loop, _, start_all_func = start_comfyui()
|
||||||
try:
|
try:
|
||||||
event_loop.run_until_complete(start_all_func())
|
event_loop.run_until_complete(start_all_func())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user