Clean up utils gc/sys imports
Move to top and import the modules instead of funcs from them. Keeps the scope cleaner.
This commit is contained in:
parent
e5354a6787
commit
edbe583959
1 changed files with 4 additions and 7 deletions
|
|
@ -7,6 +7,7 @@ be of use when designing your own game.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import gc
|
||||||
import sys
|
import sys
|
||||||
import imp
|
import imp
|
||||||
import types
|
import types
|
||||||
|
|
@ -1644,10 +1645,6 @@ def get_evennia_pids():
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
from gc import get_referents
|
|
||||||
from sys import getsizeof
|
|
||||||
|
|
||||||
|
|
||||||
def deepsize(obj, max_depth=4):
|
def deepsize(obj, max_depth=4):
|
||||||
"""
|
"""
|
||||||
Get not only size of the given object, but also the size of
|
Get not only size of the given object, but also the size of
|
||||||
|
|
@ -1673,14 +1670,14 @@ def deepsize(obj, max_depth=4):
|
||||||
def _recurse(o, dct, depth):
|
def _recurse(o, dct, depth):
|
||||||
if 0 <= max_depth < depth:
|
if 0 <= max_depth < depth:
|
||||||
return
|
return
|
||||||
for ref in get_referents(o):
|
for ref in gc.get_referents(o):
|
||||||
idr = id(ref)
|
idr = id(ref)
|
||||||
if idr not in dct:
|
if idr not in dct:
|
||||||
dct[idr] = (ref, getsizeof(ref, default=0))
|
dct[idr] = (ref, sys.getsizeof(ref, default=0))
|
||||||
_recurse(ref, dct, depth + 1)
|
_recurse(ref, dct, depth + 1)
|
||||||
sizedict = {}
|
sizedict = {}
|
||||||
_recurse(obj, sizedict, 0)
|
_recurse(obj, sizedict, 0)
|
||||||
size = getsizeof(obj) + sum([p[1] for p in sizedict.values()])
|
size = sys.getsizeof(obj) + sum([p[1] for p in sizedict.values()])
|
||||||
return size
|
return size
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue