From c96085204d5298235e46e737be76ea27800c5eb0 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Fri, 12 Apr 2024 19:55:17 -0700 Subject: [PATCH] Revert "Add flag for supporting running comfy as a script" This reverts commit 44631bc3af0a6d2f37cc8017b0000da30069a297. --- comfy/cli_args.py | 8 +------- execution.py | 7 ------- main.py | 9 --------- server.py | 47 ++++------------------------------------------- 4 files changed, 5 insertions(+), 66 deletions(-) diff --git a/comfy/cli_args.py b/comfy/cli_args.py index 066335b82..353bb51e7 100644 --- a/comfy/cli_args.py +++ b/comfy/cli_args.py @@ -1,7 +1,5 @@ import argparse -import base64 import enum -import json import comfy.options class EnumAction(argparse.Action): @@ -109,12 +107,8 @@ parser.add_argument("--disable-smart-memory", action="store_true", help="Force C parser.add_argument("--deterministic", action="store_true", help="Make pytorch use slower deterministic algorithms when it can. Note that this might not make images deterministic in all cases.") parser.add_argument("--dont-print-server", action="store_true", help="Don't print server output.") +parser.add_argument("--quick-test-for-ci", action="store_true", help="Quick test for CI.") parser.add_argument("--windows-standalone-build", action="store_true", help="Windows standalone build: Enable convenient things that most people using the standalone windows build will probably enjoy (like auto opening the page on startup).") -ci_group = parser.add_mutually_exclusive_group() -ci_group.add_argument("--quick-test-for-ci", action="store_true", help="Quick test for CI.") -ci_group.add_argument("--test-ci-with-prompts", action="store_true", help="Test CI with prompts and Comfy will stop running after prompts are complete.") -parser.add_argument("--prompts-for-ci-test", nargs="+", default=[], type=lambda x: json.loads(base64.b64decode(x).decode("utf-8")), help="List of base64 encoded JSON strings for testing CI with prompts. Prompts to use for CI test when --test-ci-with-prompts is set.") - parser.add_argument("--disable-metadata", action="store_true", help="Disable saving prompt metadata in files.") diff --git a/execution.py b/execution.py index 5d7c856c2..35bdb77a6 100644 --- a/execution.py +++ b/execution.py @@ -721,7 +721,6 @@ class PromptQueue: self.history = {} self.flags = {} server.prompt_queue = self - self.stop_server_upon_completion = False def put(self, item): with self.mutex: @@ -764,8 +763,6 @@ class PromptQueue: 'status': status_dict, } self.server.queue_updated() - if self.stop_server_upon_completion and len(self.queue) == 0 and len(self.currently_running) == 0: - self.server.stop() def get_current_queue(self): with self.mutex: @@ -822,10 +819,6 @@ class PromptQueue: def delete_history_item(self, id_to_delete): with self.mutex: self.history.pop(id_to_delete, None) - - def set_stop_server_upon_completion(self, value): - with self.mutex: - self.stop_server_upon_completion = value def set_flag(self, name, data): with self.mutex: diff --git a/main.py b/main.py index ec2ad0461..b3a3ebea8 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -import uuid import comfy.options comfy.options.enable_args_parsing() @@ -242,14 +241,6 @@ if __name__ == "__main__": if args.quick_test_for_ci: exit(0) - if args.test_ci_with_prompts: - q.set_stop_server_upon_completion(True) - for prompt_json in args.prompts_for_ci_test: - prompt_id = str(uuid.uuid4()) - validation = execution.validate_prompt(prompt_json) - outputs_to_execute = validation[2] - q.put((0, prompt_id, prompt_json, {}, outputs_to_execute)) - call_on_start = None if args.auto_launch: def startup_server(address, port): diff --git a/server.py b/server.py index 7ae2634cc..5642bd5e2 100644 --- a/server.py +++ b/server.py @@ -73,8 +73,6 @@ class PromptServer(): self.loop = loop self.messages = asyncio.Queue() self.number = 0 - self.runner = None - self.site = None middlewares = [cache_control] if args.enable_cors_header: @@ -477,7 +475,6 @@ class PromptServer(): if valid[0]: prompt_id = str(uuid.uuid4()) outputs_to_execute = valid[2] - # TODO: refactor PromptQueue to take typed input self.prompt_queue.put((number, prompt_id, prompt, extra_data, outputs_to_execute)) response = {"prompt_id": prompt_id, "number": number, "node_errors": valid[3]} return web.json_response(response) @@ -621,16 +618,13 @@ class PromptServer(): async def publish_loop(self): while True: msg = await self.messages.get() - # Break the message loop with None message - if msg is None: - break await self.send(*msg) async def start(self, address, port, verbose=True, call_on_start=None): - self.runner = web.AppRunner(self.app, access_log=None) - await self.runner.setup() - self.site = web.TCPSite(self.runner, address, port) - await self.site.start() + runner = web.AppRunner(self.app, access_log=None) + await runner.setup() + site = web.TCPSite(runner, address, port) + await site.start() if verbose: logging.info("Starting server\n") @@ -638,39 +632,6 @@ class PromptServer(): if call_on_start is not None: call_on_start(address, port) - # TODO: accept stop API request - def stop(self): - """ - Stop the server. - - Call `async_stop` coroutine in a thread-safe manner - If the event loop is not running, the stop() is called too early - """ - logging.info("Stopping server") - if self.loop.is_running(): - asyncio.run_coroutine_threadsafe(self.async_stop(), self.loop) - else: - logging.error("Cannot stop server, loop is not running") - - - async def async_stop(self): - """ - Asynchronously stops the server. - This coroutine should be called to gracefully stop the server. - """ - # Put breaking message for message queue - await self.messages.put(None) - # TODO: check if queue is not yet complete and conditional shutdown - # server - if not self.site or self.site._closed: # Check if the site is already closed - logging.warning("Server is already stopped or was never started.") - return - if self.site: - await self.site.stop() - if self.runner: - await self.runner.cleanup() - logging.info("Stopped site upon request") - def add_on_prompt_handler(self, handler): self.on_prompt_handlers.append(handler)