Skip to content

Commit

Permalink
Cache executor to avoid hitting open file limits (#4560)
Browse files Browse the repository at this point in the history
Fixes #4504, fixes #3251
  • Loading branch information
hauntsaninja authored Jan 25, 2025
1 parent c0b92f3 commit 99dbf30
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/blackd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from concurrent.futures import Executor, ProcessPoolExecutor
from datetime import datetime, timezone
from functools import partial
from functools import cache, partial
from multiprocessing import freeze_support

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


@cache
def executor() -> Executor:
return ProcessPoolExecutor()


def make_app() -> web.Application:
app = web.Application(
middlewares=[cors(allow_headers=(*BLACK_HEADERS, "Content-Type"))]
)
executor = ProcessPoolExecutor()
app.add_routes([web.post("/", partial(handle, executor=executor))])
app.add_routes([web.post("/", partial(handle, executor=executor()))])
return app


Expand Down

0 comments on commit 99dbf30

Please sign in to comment.