Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a regression in handling processes that fork #645

Merged
merged 2 commits into from
Jul 3, 2024
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.13.2
current_version = 1.13.3
commit = True
message =
Prepare for {new_version} release
Expand Down
9 changes: 9 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ Changelog

.. towncrier release notes start

memray 1.13.3 (2024-07-02)
--------------------------

Bug Fixes
~~~~~~~~~

- Fix a bug that could result in truncated reports for applications that fork without calling :c:func:`PyOS_BeforeFork`, including by using `multiprocessing` with the "spawn" start method (the default on macOS). (#644)


memray 1.13.2 (2024-06-27)
--------------------------

Expand Down
16 changes: 11 additions & 5 deletions src/memray/_memray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ from ._metadata import Metadata
from ._stats import Stats
from ._thread_name_interceptor import ThreadNameInterceptor

os.register_at_fork(
before=NativeTracker.prepareFork,
after_in_parent=NativeTracker.parentFork,
after_in_child=NativeTracker.childFork,
)

cdef extern from "pthread.h" nogil:
int pthread_atfork(void (*prepare)(), void (*parent)(), void (*child)())

# NOTE: We can't reinitialize tracking in a child process until the interpreter
# has reinitialized its locks, so we do it in a Python fork handler.
# But, Python fork handlers aren't guaranteed to run for every fork, and
# the child process must never inherit an active tracker, so we must use
# a pthread fork handler to disable tracking before forking.
pthread_atfork(&NativeTracker.prepareFork, &NativeTracker.parentFork, NULL)
os.register_at_fork(after_in_child=NativeTracker.childFork)


def set_log_level(int level):
Expand Down
6 changes: 3 additions & 3 deletions src/memray/_memray/tracking_api.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ cdef extern from "tracking_api.h" namespace "memray::tracking_api":
void registerThreadNameById(uint64_t, const char*) except+

@staticmethod
void prepareFork() noexcept
void prepareFork() noexcept nogil

@staticmethod
void parentFork() noexcept
void parentFork() noexcept nogil

@staticmethod
void childFork() noexcept
void childFork() noexcept nogil
2 changes: 1 addition & 1 deletion src/memray/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.13.2"
__version__ = "1.13.3"
Loading