Meshtastic

Python TCP interface.close() blocking for arbitrary amount of time

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

Also… happy new year :slight_smile:

3 Likes

Happy new year to you too!

3 Likes

Hmm. Interesting! I wonder if I’m shutting down the server side correctly. Can you convert this into a bug on meshtastic-python and I’ll take a look soon. I suspect watching the serial debug log as this test is running will give a clue.

1 Like

Sure I’ll submit. Do you prefer (in general) that I post here before I log bugs/issues or should I just log whatever I find as I work through this stuff? I never know whats worthy of an official issue vs. just forum level activity.

Fwiw, serial console is pretty devoid of info. Api server shows seemingly normal output. But I’ll attach the output all the same.

either here or github is fine. But once it looks like a bug is probably present at least one github issue is good, because otherwise I might forget things.