mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-09-05 02:24:21 -05:00
* add inline executor and an option to run single-threaded * add option to run test_full_sync in single-thread mode, to include block validation in profiles. Also attempt to speed it up by disabling db_sync
25 lines
646 B
Python
25 lines
646 B
Python
from __future__ import annotations
|
|
|
|
from concurrent.futures import Executor, Future
|
|
from typing import Callable, TypeVar
|
|
|
|
_T = TypeVar("_T")
|
|
|
|
|
|
class InlineExecutor(Executor):
|
|
_closing: bool = False
|
|
|
|
def submit(self, fn: Callable[..., _T], *args, **kwargs) -> Future[_T]: # type: ignore
|
|
if self._closing:
|
|
raise RuntimeError("executor shutting down")
|
|
|
|
f: Future[_T] = Future()
|
|
try:
|
|
f.set_result(fn(*args, **kwargs))
|
|
except BaseException as e: # lgtm[py/catch-base-exception]
|
|
f.set_exception(e)
|
|
return f
|
|
|
|
def close(self) -> None:
|
|
self._closing = True
|