Skip to content

Setting connection timeout too short (<10s) throws unhandled exception #432

Closed

Description

@mikerob

I was testing out the connection timeout, and came across an odd behaviour. If I set the timeout > 10 seconds, everything works nicely - it hapily throws an APIException that I can catch.

However, if I set the connection timeout lower than that, it throws a different exception, seemingly from somewhere "inside" the connection, and it's an "Exception" rather than an "APIException".

Is this the intent? I reported it here: #407 and was requested to submit it as a new issue.

from dronekit import connect
from dronekit.lib import APIException

try:
vehicle=connect('/dev/ttyAMA0', heartbeat_timeout=10)
except APIException as ai:
print "APIException fail - Something bad happened"
print type(ai)
print ai.args
print ai.msg
except Exception as ai:
print "Something we didn't expect"
print type(ai)
print ai.args
print ai
else:
print "It worked"

If I set timeout to 10 or more, it works fine. If less than that, it throws the following:
pi@MavStation ~/pigs $ python to_exc.py

Link timeout, no heartbeat in last 5 seconds
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 505, in run
self.__target(self.__args, *self.__kwargs)
File "/usr/local/lib/python2.7/dist-packages/dronekit-2.0.0rc7-py2.7.egg/drone
kit/__init.py", line 77, in mavlink_thread
fn(self)
File "/usr/local/lib/python2.7/dist-packages/dronekit-2.0.0rc7-py2.7.egg/drone
kit/lib/init.py", line 855, in listener
raise Exception('>>> No heartbeat in %s seconds, aborting.' % self._heartbea
t_error)
Exception: >>> No heartbeat in 9 seconds, aborting.

APIException fail - Something bad happened

()
Timeout in initializing connection.

It looks like setting timeout too low interferes with or gets inside some other exception handling loop.

Activity

  1. tcr3dr commented on Nov 9, 2015

    @tcr3dr
    Contributor

    Thanks for filing this, @mikerob. This is definitely a weird case for exceptions—one being throw on the MAVLink thread, another interrupting the main thread—so let me put together a proposed solution for this that is catchable.

  2. modified the milestone: v2.0.0 on Nov 10, 2015
  3. hamishwillee commented on Nov 11, 2015

    @hamishwillee
    Contributor

    Hi @mikerob

    YOu might want to try out the branch in #447, which @tcr3dr thinks improves this issue.

  4. tcr3dr commented on Nov 11, 2015

    @tcr3dr
    Contributor

    Note this is now on master.

  5. mikerob commented on Nov 12, 2015

    @mikerob
    Author

    @tcr3dr Thanks Tim - looks like it's working now. Do I "close" this, or do you?

    I've got some test code in here: https://github.com/mikerob/dronekit-python/tree/master/pigs if you're interested

  6. tcr3dr commented on Nov 17, 2015

    @tcr3dr
    Contributor

    I can close it. Thanks for the test code! This is helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions