Closed VictorEmelin closed 1 month ago
You need to fix it by increasing wait time in
tbot/tbot/machine/channel/subprocess.py
line 118
Why did you limit exponential backoff to 1 sec? It could be greater without affecting anything else
For me for t in range(11):
works perfect. range(7)
not enough.
Hi,
the backoff limit was intentionally chosen to be quite low because usually, when subprocesses don't stop, the correct solution is to add code that cleanly terminates the offending processes. In your case, the solution is probably to send a termination escape sequence to picocom:
def connect(self, mach):
ch = mach.open_channel("picocom", "-b", str(self.baudrate), self.serial_port)
try:
yield ch
finally:
ch.sendcontrol("A")
ch.sendcontrol("Q")
That said, I'd be open to extending the backoff time a bit but displaying a warning after one second that something isn't right.
@Rahix thanks for your suggestion (just contextlib.contextmanager decorator is needed to add). It works, but it works even this way:
@contextlib.contextmanager
def connect(self, mach):
ch = mach.open_channel("picocom", "-b", str(self.baudrate), self.serial_port)
yield ch
Didn't dive deep to it.
And in both cases it can raise tbot.error.ChannelClosedError if spam this test very often. Maybe it's not important but increasing backoff time doesn't have this problem (for t in range(8):
was enough for me)
So maybe worth it to extend backoff time or to add the trick above to documentation. Up to you.
but it works even this way:
Yeah, it is a timing race between tbot's timeout and your picocom process stopping. It will work some days and some days it will fail.
To avoid ugly situations like this, I have taken great care to not make use of timeouts in tbot whereever possible. You ran into one of the few remaining ones...
I have now created #120 to hopefully improve on this. Please let me know if this works for you.
or to add the trick above to documentation
So I think the real solution here is to add a dedicated picocom connector to tbot, which implements this behavior instead of just documenting what people need to do.
And actually, this picocom connector already exists - in a way: The AutoConsoleConnector
from tbot_contrib
includes support for picocom
, using the exact code I showed above. But as I just noticed, this connector never made it into the documentation :face_with_peeking_eye: Need to fix that asap...
AutoConsoleConnector
is documented now: https://tbot.tools/contrib/connector.html#tbot_contrib.connector.auto.AutoConsoleConnector
Very simple test case fails with error:
code hello_world.py:
code temp_config.py: