diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py index 4acf1cc81d..bdb4183499 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py @@ -22,6 +22,7 @@ from threading import Event, Lock, RLock, Thread from time import time_ns from typing import IO, Callable, Dict, Iterable, Optional +import weakref from typing_extensions import final @@ -490,8 +491,9 @@ def __init__( ) self._daemon_thread.start() if hasattr(os, "register_at_fork"): + weakself = weakref.proxy(self) os.register_at_fork( - after_in_child=self._at_fork_reinit + after_in_child=lambda: weakself._at_fork_reinit() ) # pylint: disable=protected-access elif self._export_interval_millis <= 0: raise ValueError(