@@ -101,6 +101,7 @@ def __init__(self, mode: typing.Literal["online", "offline"] = "online") -> None
101
101
self ._simvue : typing .Optional [SimvueBaseClass ] = None
102
102
self ._pid : typing .Optional [int ] = 0
103
103
self ._shutdown_event : typing .Optional [threading .Event ] = None
104
+ self ._configuration_lock = threading .Lock ()
104
105
self ._heartbeat_termination_trigger : typing .Optional [threading .Event ] = None
105
106
self ._storage_id : typing .Optional [str ] = None
106
107
self ._heartbeat_thread : typing .Optional [threading .Thread ] = None
@@ -226,18 +227,19 @@ def _heartbeat(
226
227
while not heartbeat_trigger .is_set ():
227
228
time .sleep (0.1 )
228
229
229
- if (
230
- self ._resources_metrics_interval
231
- and (res_time := time .time ()) - last_res_metric_call
232
- > self ._resources_metrics_interval
233
- ):
234
- # Set join on fail to false as if an error is thrown
235
- # join would be called on this thread and a thread cannot
236
- # join itself!
237
- self ._add_metrics_to_dispatch (
238
- self ._get_sysinfo (), join_on_fail = False
239
- )
240
- last_res_metric_call = res_time
230
+ with self ._configuration_lock :
231
+ if (
232
+ self ._resources_metrics_interval
233
+ and (res_time := time .time ()) - last_res_metric_call
234
+ > self ._resources_metrics_interval
235
+ ):
236
+ # Set join on fail to false as if an error is thrown
237
+ # join would be called on this thread and a thread cannot
238
+ # join itself!
239
+ self ._add_metrics_to_dispatch (
240
+ self ._get_sysinfo (), join_on_fail = False
241
+ )
242
+ last_res_metric_call = res_time
241
243
242
244
if time .time () - last_heartbeat < HEARTBEAT_INTERVAL :
243
245
continue
@@ -797,27 +799,28 @@ def config(
797
799
_description_
798
800
"""
799
801
800
- if suppress_errors is not None :
801
- self ._suppress_errors = suppress_errors
802
+ with self ._configuration_lock :
803
+ if suppress_errors is not None :
804
+ self ._suppress_errors = suppress_errors
802
805
803
- if queue_blocking is not None :
804
- self ._queue_blocking = queue_blocking
806
+ if queue_blocking is not None :
807
+ self ._queue_blocking = queue_blocking
805
808
806
- if resources_metrics_interval and disable_resources_metrics :
807
- self ._error (
808
- "Setting of resource metric interval and disabling resource metrics is ambiguous"
809
- )
810
- return False
809
+ if resources_metrics_interval and disable_resources_metrics :
810
+ self ._error (
811
+ "Setting of resource metric interval and disabling resource metrics is ambiguous"
812
+ )
813
+ return False
811
814
812
- if disable_resources_metrics :
813
- self ._pid = None
814
- self ._resources_metrics_interval = None
815
+ if disable_resources_metrics :
816
+ self ._pid = None
817
+ self ._resources_metrics_interval = None
815
818
816
- if resources_metrics_interval :
817
- self ._resources_metrics_interval = resources_metrics_interval
819
+ if resources_metrics_interval :
820
+ self ._resources_metrics_interval = resources_metrics_interval
818
821
819
- if storage_id :
820
- self ._storage_id = storage_id
822
+ if storage_id :
823
+ self ._storage_id = storage_id
821
824
822
825
return True
823
826
0 commit comments