Skip to content

Commit

Permalink
fix: Prevent multiple locks being created per process, side-stepping …
Browse files Browse the repository at this point in the history
…locks.
matthewwardrop committed Nov 30, 2023
1 parent 437545f commit 2d47b3a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec_classes/utils/mutation.py
Original file line number Diff line number Diff line change
@@ -51,6 +51,14 @@ class _modules_copyable:
context switches.
"""

def __new__(cls, *args, **kwargs):
"""
Make this class a singleton (there exists at most one instance).
"""
if not hasattr(cls, "__instance__"):
cls.__instance__ = super().__new__(cls, *args, **kwargs)
return cls.__instance__

def __init__(self):
self.lock = RLock()
self.refcount = 0
@@ -69,6 +77,7 @@ def __exit__(self, *args):
self.refcount -= 1
if self.patched_table and self.refcount == 0:
del copyreg.dispatch_table[ModuleType]
self.patched_table = False


def mutate_attr(

0 comments on commit 2d47b3a

Please sign in to comment.