From b954910b0896ce2cab266b72797824df199d2404 Mon Sep 17 00:00:00 2001 From: Scott Petersen Date: Fri, 31 May 2013 15:33:41 -0700 Subject: [PATCH] Terrible commit message that I couldn't even determine what it was supposed to mean. Not that this one is better, but at least it has no cursing. --- pyad2usb/devices.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pyad2usb/devices.py b/pyad2usb/devices.py index ecfba05..8f38dd4 100644 --- a/pyad2usb/devices.py +++ b/pyad2usb/devices.py @@ -207,7 +207,6 @@ class USBDevice(Device): """ def timeout_event(): timeout_event.reading = False - raise util.TimeoutError('Timeout while waiting for line terminator.') timeout_event.reading = True @@ -250,7 +249,10 @@ class USBDevice(Device): self.on_read(ret) if timer: - timer.cancel() + if timer.is_alive(): + timer.cancel() + else: + raise util.TimeoutError('Timeout while waiting for line terminator.') return ret @@ -393,7 +395,6 @@ class SerialDevice(Device): def timeout_event(): timeout_event.reading = False - raise util.TimeoutError('Timeout while waiting for line terminator.') timeout_event.reading = True @@ -436,7 +437,10 @@ class SerialDevice(Device): self.on_read(ret) if timer: - timer.cancel() + if timer.is_alive(): + timer.cancel() + else: + raise util.TimeoutError('Timeout while waiting for line terminator.') return ret @@ -552,7 +556,6 @@ class SocketDevice(Device): """ def timeout_event(): timeout_event.reading = False - raise util.TimeoutError('Timeout while waiting for line terminator.') timeout_event.reading = True @@ -595,6 +598,9 @@ class SocketDevice(Device): self.on_read(ret) if timer: - timer.cancel() + if timer.is_alive(): + timer.cancel() + else: + raise util.TimeoutError('Timeout while waiting for line terminator.') return ret