mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 11:28:14 +00:00
src/trezor/utils: replace unimport with explicit fns, remove parent references
This commit is contained in:
parent
9b9183c4f7
commit
b38d6870eb
@ -4,18 +4,24 @@ import gc
|
|||||||
from trezorutils import halt, memcpy, set_mode_unprivileged, symbol, model # noqa: F401
|
from trezorutils import halt, memcpy, set_mode_unprivileged, symbol, model # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
def unimport(genfunc):
|
def unimport_begin():
|
||||||
async def inner(*args, **kwargs):
|
return set(sys.modules)
|
||||||
mods = set(sys.modules)
|
|
||||||
try:
|
|
||||||
ret = await genfunc(*args, **kwargs)
|
def unimport_end(mods):
|
||||||
finally:
|
for mod in sys.modules:
|
||||||
for mod in sys.modules:
|
if mod not in mods:
|
||||||
if mod not in mods:
|
# remove reference from sys.modules
|
||||||
del sys.modules[mod]
|
del sys.modules[mod]
|
||||||
gc.collect()
|
# remove reference from the parent module
|
||||||
return ret
|
i = mod.rfind('.')
|
||||||
return inner
|
if i < 0:
|
||||||
|
continue
|
||||||
|
path = mod[:i]
|
||||||
|
name = mod[i + 1:]
|
||||||
|
delattr(sys.modules[path], name)
|
||||||
|
# collect removed modules
|
||||||
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
def ensure(cond, msg=None):
|
def ensure(cond, msg=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user