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

Lines changed: 7 additions & 3 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy