Skip to content

Commit

Permalink
refactor: remove max threads param
Browse files Browse the repository at this point in the history
  • Loading branch information
hartungstenio committed Sep 19, 2023
1 parent db19eeb commit b51a1d2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ UNRELEASED
----------
* refactor: remove ConfigurationError exception
* refactor: remove concurrency limit param
* refactor: remove max threads param

4.0.0 (2023-07-10)
------------------
Expand Down
4 changes: 2 additions & 2 deletions loafer/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@


class LoaferManager:
def __init__(self, routes, runner=None, _max_threads=None):
def __init__(self, routes, runner=None):
if runner is None:
self.runner = LoaferRunner(on_stop_callback=self.on_loop__stop, max_workers=_max_threads)
self.runner = LoaferRunner(on_stop_callback=self.on_loop__stop)
else:
self.runner = runner

Expand Down
12 changes: 2 additions & 10 deletions loafer/runners.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import asyncio
import logging
import signal
from concurrent.futures import CancelledError, ThreadPoolExecutor
from concurrent.futures import CancelledError
from contextlib import suppress

logger = logging.getLogger(__name__)


class LoaferRunner:
def __init__(self, max_workers=None, on_stop_callback=None):
def __init__(self, on_stop_callback=None):
self._on_stop_callback = on_stop_callback

# XXX: See https://github.com/python/asyncio/issues/258
# The minimum value depends on the number of cores in the machine
# See https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor
self._executor = ThreadPoolExecutor(max_workers)
self.loop.set_default_executor(self._executor)

@property
def loop(self):
return asyncio.get_event_loop()
Expand Down Expand Up @@ -69,5 +63,3 @@ def stop(self, *args, **kwargs):
logger.info("cancel schedulled operations ...")
with suppress(CancelledError, RuntimeError):
self._cancel_all_tasks()

self._executor.shutdown(wait=True)

0 comments on commit b51a1d2

Please sign in to comment.