mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-10 14:20:49 +08:00
Always use spawn context, even on Linux
This commit is contained in:
parent
2fd5fc81f5
commit
583ddd6b38
@ -2,6 +2,7 @@ import concurrent.futures
|
|||||||
import contextvars
|
import contextvars
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import pickle
|
import pickle
|
||||||
|
import logging
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Callable, Any
|
from typing import Callable, Any
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ from pebble import ProcessPool, ProcessFuture
|
|||||||
|
|
||||||
from ..component_model.executor_types import Executor
|
from ..component_model.executor_types import Executor
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def _wrap_with_context(context_data: bytes, func: Callable, *args, **kwargs) -> Any:
|
def _wrap_with_context(context_data: bytes, func: Callable, *args, **kwargs) -> Any:
|
||||||
new_ctx: contextvars.Context = pickle.loads(context_data)
|
new_ctx: contextvars.Context = pickle.loads(context_data)
|
||||||
@ -22,8 +24,9 @@ class ProcessPoolExecutor(ProcessPool, Executor):
|
|||||||
initializer: Callable = None,
|
initializer: Callable = None,
|
||||||
initargs: list | tuple = (),
|
initargs: list | tuple = (),
|
||||||
context: multiprocessing.context.BaseContext = None):
|
context: multiprocessing.context.BaseContext = None):
|
||||||
if context is None:
|
if context is not None:
|
||||||
context = multiprocessing.get_context('spawn')
|
logger.warning(f"A context was passed to a ProcessPoolExecutor when only spawn is supported (context={context})")
|
||||||
|
context = multiprocessing.get_context('spawn')
|
||||||
super().__init__(max_workers=max_workers, max_tasks=max_tasks, initializer=initializer, initargs=initargs, context=context)
|
super().__init__(max_workers=max_workers, max_tasks=max_tasks, initializer=initializer, initargs=initargs, context=context)
|
||||||
|
|
||||||
def shutdown(self, wait=True, *, cancel_futures=False):
|
def shutdown(self, wait=True, *, cancel_futures=False):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user