File tree 1 file changed +13
-10
lines changed
1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change 8
8
from datetime import datetime
9
9
from time import sleep
10
10
from sys import version_info
11
+ from multiprocessing import Lock
11
12
12
13
from xbee import ZigBee as ZigBeeDevice
13
14
@@ -88,6 +89,7 @@ class ZigBee(object):
88
89
"""
89
90
_rx_frames = {}
90
91
_frame_id = 1
92
+ _lock = Lock ()
91
93
92
94
def __init__ (self , ser ):
93
95
self ._ser = ser
@@ -140,16 +142,17 @@ def _send_and_wait(self, **kwargs):
140
142
"""
141
143
frame_id = self .next_frame_id
142
144
kwargs .update (dict (frame_id = frame_id ))
143
- self ._send (** kwargs )
144
- timeout = datetime .now () + const .RX_TIMEOUT
145
- while datetime .now () < timeout :
146
- try :
147
- frame = self ._rx_frames .pop (frame_id )
148
- raise_if_error (frame )
149
- return frame
150
- except KeyError :
151
- sleep (0.1 )
152
- continue
145
+ with self ._lock :
146
+ self ._send (** kwargs )
147
+ timeout = datetime .now () + const .RX_TIMEOUT
148
+ while datetime .now () < timeout :
149
+ try :
150
+ frame = self ._rx_frames .pop (frame_id )
151
+ raise_if_error (frame )
152
+ return frame
153
+ except KeyError :
154
+ sleep (0.1 )
155
+ continue
153
156
_LOGGER .exception (
154
157
"Did not receive response within configured timeout period." )
155
158
raise exceptions .ZigBeeResponseTimeout ()
You can’t perform that action at this time.
0 commit comments