File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,10 @@ def __init__(
151
151
self ._timer : float = 0
152
152
self ._retention : float | None = None
153
153
154
+ # Keep track of if the Run class has been intialised
155
+ # through a context manager
156
+ self ._context_manager_called : bool = False
157
+
154
158
self ._testing : bool = False
155
159
self ._abort_on_alert : typing .Literal ["run" , "terminate" , "ignore" ] = "terminate"
156
160
self ._abort_callback : typing .Callable [[Self ], None ] | None = abort_callback
@@ -209,6 +213,7 @@ def __init__(
209
213
self ._emissions_monitor : CO2Monitor | None = None
210
214
211
215
def __enter__ (self ) -> Self :
216
+ self ._context_manager_called = True
212
217
return self
213
218
214
219
def _handle_exception_throw (
@@ -1659,6 +1664,10 @@ def close(self) -> bool:
1659
1664
bool
1660
1665
whether close was successful
1661
1666
"""
1667
+ if self ._context_manager_called :
1668
+ self ._error ("Cannot call close method in context manager." )
1669
+ return
1670
+
1662
1671
self ._executor .wait_for_completion ()
1663
1672
1664
1673
if not self ._sv_obj :
You can’t perform that action at this time.
0 commit comments