Skip to content

Commit

Permalink
Make asyncio default task impl (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Jan 29, 2025
1 parent 4a461dc commit 38fbe8c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions granian/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ._futures import _future_watcher_wrapper, _new_cbscheduler
from ._granian import ASGIWorker, RSGIWorker, WSGIWorker
from ._imports import anyio, setproctitle, watchfiles
from ._imports import setproctitle, watchfiles
from ._internal import load_target
from ._signals import set_main_signals
from .asgi import LifespanProtocol, _callback_wrapper as _asgi_call_wrap
Expand Down Expand Up @@ -728,8 +728,12 @@ def serve(
logger.error('Workers lifetime cannot be less than 60 seconds')
raise ConfigurationError('workers_lifetime')

# FIXME: `rust` impl seems to mem-leak
if self.task_impl == TaskImpl.auto:
self.task_impl = TaskImpl.asyncio if anyio is not None else TaskImpl.rust
# self.task_impl = TaskImpl.asyncio if anyio is not None else TaskImpl.rust
self.task_impl = TaskImpl.asyncio
if self.task_impl == TaskImpl.rust:
logger.warning('Rust task implementation is still experimental and might cause memory leaks!')

serve_method = self._serve_with_reloader if self.reload_on_changes else self._serve
serve_method(spawn_target, target_loader)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extend-ignore = [
'S110', # except pass is fine
]
flake8-quotes = { inline-quotes = 'single', multiline-quotes = 'double' }
mccabe = { max-complexity = 14 }
mccabe = { max-complexity = 15 }

[tool.ruff.format]
quote-style = 'single'
Expand Down
2 changes: 1 addition & 1 deletion tests/apps/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,5 @@ def app(scope, receive, send):
'/err_app': err_app,
'/err_proto': err_proto,
'/timeout_n': timeout_n,
'/timeout_w': timeout_w
'/timeout_w': timeout_w,
}.get(scope['path'], info)(scope, receive, send)

0 comments on commit 38fbe8c

Please sign in to comment.