Fixed potential case of GC crippling
Cite: https://docs.python.org/3/library/inspect.html#the-interpreter-stack
This commit is contained in:
parent
dc3a34651f
commit
f2b509f9fa
@ -3,6 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
IO stuff.
|
IO stuff.
|
||||||
"""
|
"""
|
||||||
|
import copy
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -45,10 +46,17 @@ def in_here(first_path_bit: str, *path_bits: str, stack_depth: int=0) -> str:
|
|||||||
module = inspect.getmodule(frame[0])
|
module = inspect.getmodule(frame[0])
|
||||||
assert hasattr(module, '__file__'), 'No `__file__\' attr, welp.'
|
assert hasattr(module, '__file__'), 'No `__file__\' attr, welp.'
|
||||||
|
|
||||||
|
# https://docs.python.org/3/library/inspect.html#the-interpreter-stack
|
||||||
|
# If Python caches strings rather than copying when we move them
|
||||||
|
# around or modify them, then this may cause a referential cycle which
|
||||||
|
# will consume more memory and stop the garbage collection system
|
||||||
|
# from working correctly. Best thing to do here is deepcopy anything
|
||||||
|
# we need and prevent this occuring. Del the references to allow them
|
||||||
|
# to be freed.
|
||||||
file = module.__file__
|
file = module.__file__
|
||||||
|
file = copy.deepcopy(file)
|
||||||
|
del module, frame
|
||||||
dir_name = os.path.dirname(file)
|
dir_name = os.path.dirname(file)
|
||||||
abs_dir_name = os.path.abspath(dir_name)
|
abs_dir_name = os.path.abspath(dir_name)
|
||||||
|
|
||||||
pathish = os.path.join(abs_dir_name, first_path_bit, *path_bits)
|
pathish = os.path.join(abs_dir_name, first_path_bit, *path_bits)
|
||||||
return pathish
|
return pathish
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user