Skip to content

Commit 5b580ad

Browse files
committed
Fix bug with cached imports in utils
1 parent 4d0089b commit 5b580ad

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

labscript/utils.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
from .compiler import compiler
88

9-
_RemoteConnection = None
10-
ClockLine = None
11-
PseudoClockDevice = None
9+
cached_RemoteConnection = None
10+
cached_ClockLine = None
11+
cached_PseudoclockDevice = None
1212

1313

1414
def is_remote_connection(connection):
@@ -19,9 +19,11 @@ def is_remote_connection(connection):
1919
maintaining reasonable performance (this performs better than importing each time as
2020
the lookup in the modules hash table is slower).
2121
"""
22-
if _RemoteConnection is None:
22+
global cached_RemoteConnection
23+
if cached_RemoteConnection is None:
2324
from .remote import _RemoteConnection
24-
return isinstance(connection, _RemoteConnection)
25+
cached_RemoteConnection = _RemoteConnection
26+
return isinstance(connection, cached_RemoteConnection)
2527

2628

2729
def is_clock_line(device):
@@ -32,22 +34,26 @@ def is_clock_line(device):
3234
maintaining reasonable performance (this performs better than importing each time as
3335
the lookup in the modules hash table is slower).
3436
"""
35-
if ClockLine is None:
37+
global cached_ClockLine
38+
if cached_ClockLine is None:
3639
from .core import ClockLine
37-
return isinstance(device, _RemoteConnection)
40+
cached_ClockLine = ClockLine
41+
return isinstance(device, cached_ClockLine)
3842

3943

4044
def is_pseudoclock_device(device):
4145
"""Returns whether the connection is an instance of ``PseudoclockDevice``
4246
43-
This function defers and caches the import of ``_RemoteConnection``. This both
44-
breaks the circular import between ``Device`` and ``_RemoteConnection``, while
47+
This function defers and caches the import of ``PseudoclockDevice``. This both
48+
breaks the circular import between ``Device`` and ``PseudoclockDevice``, while
4549
maintaining reasonable performance (this performs better than importing each time as
4650
the lookup in the modules hash table is slower).
4751
"""
48-
if PseudoclockDevice is None:
52+
global cached_PseudoclockDevice
53+
if cached_PseudoclockDevice is None:
4954
from .core import PseudoclockDevice
50-
return isinstance(device, PseudoclockDevice)
55+
cached_PseudoclockDevice = PseudoclockDevice
56+
return isinstance(device, cached_PseudoclockDevice)
5157

5258

5359
def set_passed_properties(property_names=None):
@@ -182,7 +188,7 @@ def bitfield(arrays,dtype):
182188
return y
183189

184190

185-
@contextlib.contextmanager()
191+
@contextlib.contextmanager
186192
def suppress_mild_warnings(state=True):
187193
"""A context manager which modifies compiler.suppress_mild_warnings
188194
@@ -199,7 +205,7 @@ def suppress_mild_warnings(state=True):
199205
compiler.suppress_mild_warnings = previous_warning_setting
200206

201207

202-
@contextlib.contextmanager()
208+
@contextlib.contextmanager
203209
def suppress_all_warnings(state=True):
204210
"""A context manager which modifies compiler.suppress_all_warnings
205211

0 commit comments

Comments
 (0)