Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions dronekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import platform
import re
import dronekit.lib
from dronekit.lib import APIException
from dronekit.util import errprinter
from pymavlink import mavutil, mavwp
from Queue import Queue, Empty
Expand Down Expand Up @@ -60,6 +61,7 @@ def __init__(self, master, vehicle_class=Vehicle):
# Debug flag.
self._accept_input = True
self._alive = True
self._death_error = None

import atexit
def onexit():
Expand All @@ -85,8 +87,7 @@ def mavlink_thread():
except socket.error as error:
# If connection reset (closed), stop polling.
if error.errno == ECONNABORTED:
errprinter('>>> connection aborted during read')
return
raise APIException('Connection aborting during read')
raise
except Empty:
break
Expand All @@ -100,8 +101,7 @@ def mavlink_thread():
except socket.error as error:
# If connection reset (closed), stop polling.
if error.errno == ECONNABORTED:
errprinter('>>> connection aborting during send')
return
raise APIException('Connection aborting during send')
raise
except Exception as e:
# TODO this should be more rigorous. How to avoid
Expand All @@ -116,14 +116,21 @@ def mavlink_thread():
for fn in self.message_listeners:
fn(self, msg)

except APIException as e:
errprinter('>>> ' + str(e.message))
self._alive = False
self.master.close()
self._death_error = e
return

except Exception as e:
# http://bugs.python.org/issue1856
if not self._alive:
pass
else:
self._alive = False
self.master.close()
raise
self._death_error = e

t = Thread(target=mavlink_thread)
t.daemon = True
Expand Down
8 changes: 4 additions & 4 deletions dronekit/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ class APIException(Exception):
"""
Base class for DroneKit related exceptions.

:param String msg: Message string describing the exception
:param String message: Message string describing the exception
"""

def __init__(self, msg):
self.msg = msg
def __init__(self, message):
super(APIException, self).__init__(message)

class Attitude(object):
"""
Expand Down Expand Up @@ -1005,7 +1005,7 @@ def listener(_):
# Timeouts.
if self._heartbeat_started:
if self._heartbeat_error and self._heartbeat_error > 0 and time.time() - self._heartbeat_lastreceived > self._heartbeat_error:
raise Exception('>>> No heartbeat in %s seconds, aborting.' % self._heartbeat_error)
raise APIException('No heartbeat in %s seconds, aborting.' % self._heartbeat_error)
elif time.time() - self._heartbeat_lastreceived > self._heartbeat_warning:
if self._heartbeat_timeout == False:
errprinter('>>> Link timeout, no heartbeat in last %s seconds' % self._heartbeat_warning)
Expand Down