ISISComputingGroup / lewis-ess

Let's write intricate simulators!
GNU General Public License v3.0
21 stars 19 forks source link

Unsolicited replies can cause threading error #285

Open DominicOram opened 4 years ago

DominicOram commented 4 years ago

If unsolicited_reply is called periodically in a thread e.g.:

def get_data_unsolicited(self):
    timer = threading.Timer(0.1, self.get_data_unsolicited)
    timer.start
    self.handler.unsolicited_reply(b"TEST")

there will be an occasional stack trace of:

Exception in thread Thread-911:
Traceback (most recent call last):
  File "c:\instrument\apps\python\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "c:\instrument\apps\python\lib\threading.py", line 1072, in run
    self.function(*self.args, **self.kwargs)
  File "C:\Instrument\Apps\epics\support\DeviceEmulator\master\lewis_emulators\mecfrf\interfaces\stream_interface.py", line 48, in get_data_unsolicited
    handler.unsolicited_reply(b"TEST")
  File "c:\instrument\apps\python\lib\site-packages\lewis\adapters\stream.py", line 116, in unsolicited_reply
    self.push(b(reply + self._target.out_terminator))
  File "c:\instrument\apps\python\lib\asynchat.py", line 193, in push
    self.initiate_send()
  File "c:\instrument\apps\python\lib\asynchat.py", line 251, in initiate_send
    del self.producer_fifo[0]
IndexError: deque index out of range

This stack trace does not appear to affect whether the message is actually sent or not.