Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and

## Unreleased

- {pull}`739` closes file descriptors for the capture manager between CLI runs and
disposes stale database engines to prevent hitting OS file descriptor limits in
large test runs.
- {pull}`725` fixes the pickle node hash test by accounting for Python 3.14's
default pickle protocol.
- {pull}`726` adapts the interactive debugger integration to Python 3.14's
Expand Down
9 changes: 9 additions & 0 deletions src/_pytask/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from types import TracebackType

from _pytask.node_protocols import PTask
from _pytask.session import Session


@hookimpl
Expand Down Expand Up @@ -109,6 +110,14 @@ def pytask_post_parse(config: dict[str, Any]) -> None:
capman.suspend()


@hookimpl
def pytask_unconfigure(session: Session) -> None:
"""Stop capturing and release file descriptors."""
capman = session.config["pm"].get_plugin("capturemanager")
if isinstance(capman, CaptureManager):
capman.stop_capturing()


# Copied from pytest with slightly modified docstrings.


Expand Down
12 changes: 9 additions & 3 deletions src/_pytask/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from _pytask.dag_utils import node_and_neighbors

if TYPE_CHECKING:
from sqlalchemy.engine import Engine

from _pytask.node_protocols import PNode
from _pytask.node_protocols import PTask
from _pytask.session import Session
Expand All @@ -29,6 +31,7 @@


DatabaseSession = sessionmaker()
_ENGINE: Engine | None = None


class BaseTable(DeclarativeBase):
Expand All @@ -47,9 +50,12 @@ class State(BaseTable):

def create_database(url: str) -> None:
"""Create the database."""
engine = create_engine(url)
BaseTable.metadata.create_all(bind=engine)
DatabaseSession.configure(bind=engine)
global _ENGINE # noqa: PLW0603
if _ENGINE is not None:
_ENGINE.dispose()
_ENGINE = create_engine(url)
BaseTable.metadata.create_all(bind=_ENGINE)
DatabaseSession.configure(bind=_ENGINE)


def _create_or_update_state(first_key: str, second_key: str, hash_: str) -> None:
Expand Down