/usr/lib/python3/dist-packages/pyutilib/misc/gc_manager.py is in python3-pyutilib 5.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # _________________________________________________________________________
#
# PyUtilib: A Python utility library.
# Copyright (c) 2008 Sandia Corporation.
# This software is distributed under the BSD License.
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
# _________________________________________________________________________
import gc
# PauseGC is a class for clean, scoped management of the Python
# garbage collector. To disable the GC for the duration of a
# scoped block use PauseGC in combination with the Python 'with'
# statement. E.g.,
#
# def my_func():
# with PauseGC() as pgc:
# [...]
#
# When the instance falls out of scope (by termination or exception),
# the GC will be re-enabled (if it was not initially disabled). It is
# safe to nest instances of PauseGC That is, you don't have to worry
# if an outer function/method has its own instance of PauseGC.
class PauseGC(object):
__slots__ = ("reenable_gc",)
def __init__(self, pause=True):
self.reenable_gc = False
if pause:
try:
self.reenable_gc = gc.isenabled()
gc.disable()
except NotImplementedError:
# This will only happen if the Python implementation
# doesn't support disabling the GC.
pass
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
def close(self):
if self.reenable_gc:
gc.enable()
self.reenable_gc = False
|