labscript-suite / labscript-utils

Shared modules used by the 𝘭𝘒𝘣𝘴𝘀𝘳π˜ͺ𝘱𝘡 𝘴𝘢π˜ͺ𝘡𝘦. Includes a graphical exception handler, debug tools, configuration management, cross platform filepath conversions, unit conversions and custom GUI widgets.
http://labscriptsuite.org
Other
2 stars 45 forks source link

ModuleWatcher issue with import_or_reload #28

Open philipstarkey opened 4 years ago

philipstarkey commented 4 years ago

Original report (archived issue) by Chris Billington (Bitbucket: cbillington, GitHub: chrisjbillington).


Labscript compilation using import_or_reload can crash with the following after a module has been modified:

mw_bug.png

Saw this on a fresh install with Python 3.7 in miniconda, and the latest released versions of everything as of a week ago.

ispielma commented 3 years ago

I have the same issue when I compile a shot after changing a connection table, and the only solution is to restart runmanager:

Z:\K_ML\userlib\labscriptlib\K_ML\connection_table.py modified: all non-whitelisted modules will be reloaded next run. Traceback (most recent call last): File "Z:\K_ML\userlib\labscriptlib\K_ML\Cell_Fluorescence.py", line 6, in import_or_reload('labscriptlib.K_ML.connection_table') File "c:\users\rubidium\anaconda3\lib\site-packages\labscript_utils__init__.py", line 46, in import_or_reload module = importlib.import_module(modulename) File "c:\users\rubidium\anaconda3\lib\importlib__init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 971, in _find_and_load_unlocked File "", line 914, in _find_spec File "c:\users\rubidium\anaconda3\lib\site-packages\labscript_utils\double_import_denier.py", line 52, in find_spec dict_key = (fullname, tuple(path) if path is not None else None) File "", line 1174, in iter__ File "", line 1162, in _recalculate File "", line 1158, in _get_parent_path KeyError: 'labscriptlib' Compilation aborted.

zakv commented 3 years ago

I'm pretty late to the party here, but I've seen a similar bug before. I resolved it by adding empty __init__.py files to the directories in userlib wherever modules were imported from. Those files aren't in general needed for Python 3 but I've seen that some of the import machinery that labscript uses can break without them. I'm not sure that adding those files would resolve this issue as well, but it might be worth a try. If that does work, it may be worth opening another feature request issue to make the import stuff work without __init__.py files.