Initial YakPanel commit
This commit is contained in:
27
class/public/gcmanager.py
Normal file
27
class/public/gcmanager.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from .acquire import acquire
|
||||
import threading
|
||||
import gc
|
||||
|
||||
|
||||
_GC_DISABLE_COUNT = 0
|
||||
_GC_DISABLE_COUNT_LOCK = threading.Lock()
|
||||
|
||||
|
||||
# 停用GC
|
||||
def gc_disable():
|
||||
with acquire(_GC_DISABLE_COUNT_LOCK, timeout=1):
|
||||
global _GC_DISABLE_COUNT
|
||||
_GC_DISABLE_COUNT += 1
|
||||
if _GC_DISABLE_COUNT > 1:
|
||||
return
|
||||
gc.disable()
|
||||
|
||||
|
||||
# 启用GC
|
||||
def gc_enable():
|
||||
with acquire(_GC_DISABLE_COUNT_LOCK, timeout=1):
|
||||
global _GC_DISABLE_COUNT
|
||||
_GC_DISABLE_COUNT -= 1
|
||||
if _GC_DISABLE_COUNT > 0:
|
||||
return
|
||||
gc.enable()
|
||||
Reference in New Issue
Block a user