Hey, strange behavior I’m seeing from the python API when using TCPInterface. Looks like some sort of thread/locking issue. I started with a much more complex script that included some pub/sub, and threading that I thought was introducing problems so I cut it back to the most basic implementation and am still seeing the same behavior. I’m no python pro, but I don’t feel like I’m doing anything crazy here. Any feedback on what might be doing to cause my own problems?
interface.close() will generally eventually come back, but the time before it does seems arbitrary. see the two examples here:
source code
import sys
import meshtastic
import datetime
from pubsub import pub
print(str(datetime.datetime.now()) + ": start")
interface = meshtastic.TCPInterface(sys.argv[1])
print(str(datetime.datetime.now()) + ": middle")
interface.close()
print(str(datetime.datetime.now()) + ": after close")
example 1 - almost 5 minutes before .close() returns.
[root@SplunkAppBuilder ~]# python3 test.py 172.16.78.89
2021-01-01 13:39:25.715327: start
2021-01-01 13:39:25.844504: middle
2021-01-01 13:44:16.774406: after close
[root@SplunkAppBuilder ~]#
example 2 - ctrl-c
2021-01-01 13:47:42.319042: start
2021-01-01 13:47:42.563230: middle
^CTraceback (most recent call last):
File “test.py”, line 9, in
interface.close()
File “/usr/local/lib/python3.7/site-packages/meshtastic/init.py”, line 644, in close
self._rxThread.join() # wait for it to exit
File “/usr/local/lib/python3.7/threading.py”, line 1044, in join
self._wait_for_tstate_lock()
File “/usr/local/lib/python3.7/threading.py”, line 1060, in _wait_for_tstate_lock
elif lock.acquire(block, timeout):
KeyboardInterrupt
^CException ignored in: <module ‘threading’ from ‘/usr/local/lib/python3.7/threading.py’>
Traceback (most recent call last):
File “/usr/local/lib/python3.7/threading.py”, line 1307, in _shutdown
lock.acquire()
KeyboardInterrupt