Skip to content

Commit

Permalink
fix: bot.tasks memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
lxmnk committed Aug 31, 2021
1 parent 7e2cef0 commit 03a92a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions botx/bots/bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import asyncio
from dataclasses import InitVar, field
from typing import Any, Callable, Dict, List, Set
from typing import Any, Callable, Dict, List
from weakref import WeakSet

from loguru import logger
from pydantic.dataclasses import dataclass
Expand Down Expand Up @@ -49,7 +50,7 @@ class Bot( # noqa: WPS215
default_factory=dict,
)

tasks: Set[asyncio.Future] = field(init=False, default_factory=set)
tasks: WeakSet = field(init=False, default_factory=WeakSet)

async def __call__(self, message: Message) -> None:
"""Iterate through collector, find handler and execute it, running middlewares.
Expand Down
5 changes: 3 additions & 2 deletions botx/bots/mixins/lifespan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Lifespan mixin for bot."""

import asyncio
from typing import List, Set
from typing import List
from weakref import WeakSet

from botx.concurrency import callable_to_coroutine
from botx.typing import BotLifespanEvent
Expand All @@ -16,7 +17,7 @@ class LifespanMixin:
"""Lifespan events mixin for bot."""

#: currently running tasks.
tasks: Set[asyncio.Future]
tasks: WeakSet

#: startup events.
startup_events: List[BotLifespanEvent]
Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.23.1 (Aug 30, 2021)

### Fixed

* Memory leak in bot.tasks collection.


## 0.23.0 (Aug 23, 2021)

### Added
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "botx"
version = "0.23.0"
version = "0.23.1"
description = "A little python framework for building bots for eXpress"
license = "MIT"
authors = [
Expand Down

1 comment on commit 03a92a6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://pybotx.netlify.app as production
🚀 Deployed on https://612dd6b7184fda99893eaed6--pybotx.netlify.app

Please sign in to comment.