Skip to content

Commit 99dbf30

Browse files
authored
Cache executor to avoid hitting open file limits (#4560)
Fixes #4504, fixes #3251
1 parent c0b92f3 commit 99dbf30

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/blackd/__init__.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from concurrent.futures import Executor, ProcessPoolExecutor
44
from datetime import datetime, timezone
5-
from functools import partial
5+
from functools import cache, partial
66
from multiprocessing import freeze_support
77

88
try:
@@ -85,12 +85,16 @@ def main(bind_host: str, bind_port: int) -> None:
8585
web.run_app(app, host=bind_host, port=bind_port, handle_signals=True, print=None)
8686

8787

88+
@cache
89+
def executor() -> Executor:
90+
return ProcessPoolExecutor()
91+
92+
8893
def make_app() -> web.Application:
8994
app = web.Application(
9095
middlewares=[cors(allow_headers=(*BLACK_HEADERS, "Content-Type"))]
9196
)
92-
executor = ProcessPoolExecutor()
93-
app.add_routes([web.post("/", partial(handle, executor=executor))])
97+
app.add_routes([web.post("/", partial(handle, executor=executor()))])
9498
return app
9599

96100

0 commit comments

Comments
 (0)