commented-out the poll-ticking feature
not useful right now, and less code to worry about
This commit is contained in:
parent
faa6de3b75
commit
508444526a
|
@ -5,7 +5,7 @@
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
import threading as _threading
|
import threading as _threading
|
||||||
from time import time as _timestamp
|
# from time import time as _timestamp
|
||||||
|
|
||||||
# for both Python 2 and 3
|
# for both Python 2 and 3
|
||||||
try:
|
try:
|
||||||
|
@ -108,7 +108,7 @@ _EVENT_READ_TIMEOUT = 0.4 # in seconds
|
||||||
|
|
||||||
# After this many reads that did not produce a packet, call the tick() method.
|
# After this many reads that did not produce a packet, call the tick() method.
|
||||||
# This only happens if tick_period is enabled (>0) for the Listener instance.
|
# This only happens if tick_period is enabled (>0) for the Listener instance.
|
||||||
_IDLE_READS = 1 + int(5 // _EVENT_READ_TIMEOUT) # wait at least 5 seconds between ticks
|
# _IDLE_READS = 1 + int(5 // _EVENT_READ_TIMEOUT) # wait at least 5 seconds between ticks
|
||||||
|
|
||||||
|
|
||||||
class EventsListener(_threading.Thread):
|
class EventsListener(_threading.Thread):
|
||||||
|
@ -126,7 +126,7 @@ class EventsListener(_threading.Thread):
|
||||||
self._queued_notifications = _Queue(16)
|
self._queued_notifications = _Queue(16)
|
||||||
self._notifications_callback = notifications_callback
|
self._notifications_callback = notifications_callback
|
||||||
|
|
||||||
self.tick_period = 0
|
# self.tick_period = 0
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self._active = True
|
self._active = True
|
||||||
|
@ -139,10 +139,10 @@ class EventsListener(_threading.Thread):
|
||||||
|
|
||||||
self.has_started()
|
self.has_started()
|
||||||
|
|
||||||
last_tick = 0
|
# last_tick = 0
|
||||||
# the first idle read -- delay it a bit, and make sure to stagger
|
# the first idle read -- delay it a bit, and make sure to stagger
|
||||||
# idle reads for multiple receivers
|
# idle reads for multiple receivers
|
||||||
idle_reads = _IDLE_READS + (ihandle % 5) * 2
|
# idle_reads = _IDLE_READS + (ihandle % 5) * 2
|
||||||
|
|
||||||
while self._active:
|
while self._active:
|
||||||
if self._queued_notifications.empty():
|
if self._queued_notifications.empty():
|
||||||
|
@ -168,14 +168,14 @@ class EventsListener(_threading.Thread):
|
||||||
except:
|
except:
|
||||||
_log.exception("processing %s", n)
|
_log.exception("processing %s", n)
|
||||||
|
|
||||||
elif self.tick_period:
|
# elif self.tick_period:
|
||||||
idle_reads -= 1
|
# idle_reads -= 1
|
||||||
if idle_reads <= 0:
|
# if idle_reads <= 0:
|
||||||
idle_reads = _IDLE_READS
|
# idle_reads = _IDLE_READS
|
||||||
now = _timestamp()
|
# now = _timestamp()
|
||||||
if now - last_tick >= self.tick_period:
|
# if now - last_tick >= self.tick_period:
|
||||||
last_tick = now
|
# last_tick = now
|
||||||
self.tick(now)
|
# self.tick(now)
|
||||||
|
|
||||||
del self._queued_notifications
|
del self._queued_notifications
|
||||||
self.has_stopped()
|
self.has_stopped()
|
||||||
|
@ -193,9 +193,9 @@ class EventsListener(_threading.Thread):
|
||||||
"""Called right before the thread stops."""
|
"""Called right before the thread stops."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def tick(self, timestamp):
|
# def tick(self, timestamp):
|
||||||
"""Called about every tick_period seconds."""
|
# """Called about every tick_period seconds."""
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def _notifications_hook(self, n):
|
def _notifications_hook(self, n):
|
||||||
# Only consider unhandled notifications that were sent from this thread,
|
# Only consider unhandled notifications that were sent from this thread,
|
||||||
|
|
|
@ -39,7 +39,7 @@ def _ghost(device):
|
||||||
|
|
||||||
# how often to poll devices that haven't updated their statuses on their own
|
# how often to poll devices that haven't updated their statuses on their own
|
||||||
# (through notifications)
|
# (through notifications)
|
||||||
_POLL_TICK = 5 * 60 # seconds
|
# _POLL_TICK = 5 * 60 # seconds
|
||||||
|
|
||||||
|
|
||||||
class ReceiverListener(_listener.EventsListener):
|
class ReceiverListener(_listener.EventsListener):
|
||||||
|
@ -49,7 +49,7 @@ class ReceiverListener(_listener.EventsListener):
|
||||||
super(ReceiverListener, self).__init__(receiver, self._notifications_handler)
|
super(ReceiverListener, self).__init__(receiver, self._notifications_handler)
|
||||||
# no reason to enable polling yet
|
# no reason to enable polling yet
|
||||||
# self.tick_period = _POLL_TICK
|
# self.tick_period = _POLL_TICK
|
||||||
self._last_tick = 0
|
# self._last_tick = 0
|
||||||
|
|
||||||
assert status_changed_callback
|
assert status_changed_callback
|
||||||
self.status_changed_callback = status_changed_callback
|
self.status_changed_callback = status_changed_callback
|
||||||
|
@ -81,42 +81,42 @@ class ReceiverListener(_listener.EventsListener):
|
||||||
_log.exception("closing receiver %s" % r.path)
|
_log.exception("closing receiver %s" % r.path)
|
||||||
self.status_changed_callback(r) #, _status.ALERT.NOTIFICATION)
|
self.status_changed_callback(r) #, _status.ALERT.NOTIFICATION)
|
||||||
|
|
||||||
def tick(self, timestamp):
|
# def tick(self, timestamp):
|
||||||
if not self.tick_period:
|
# if not self.tick_period:
|
||||||
raise Exception("tick() should not be called without a tick_period: %s", self)
|
# raise Exception("tick() should not be called without a tick_period: %s", self)
|
||||||
|
#
|
||||||
# not necessary anymore, we're now using udev monitor to watch for receiver status
|
# # not necessary anymore, we're now using udev monitor to watch for receiver status
|
||||||
# if self._last_tick > 0 and timestamp - self._last_tick > _POLL_TICK * 2:
|
# # if self._last_tick > 0 and timestamp - self._last_tick > _POLL_TICK * 2:
|
||||||
# # if we missed a couple of polls, most likely the computer went into
|
# # # if we missed a couple of polls, most likely the computer went into
|
||||||
# # sleep, and we have to reinitialize the receiver again
|
# # # sleep, and we have to reinitialize the receiver again
|
||||||
# _log.warn("%s: possible sleep detected, closing this listener", self.receiver)
|
# # _log.warn("%s: possible sleep detected, closing this listener", self.receiver)
|
||||||
# self.stop()
|
# # self.stop()
|
||||||
# return
|
# # return
|
||||||
|
#
|
||||||
self._last_tick = timestamp
|
# self._last_tick = timestamp
|
||||||
|
#
|
||||||
try:
|
# try:
|
||||||
# read these in case they haven't been read already
|
# # read these in case they haven't been read already
|
||||||
# self.receiver.serial, self.receiver.firmware
|
# # self.receiver.serial, self.receiver.firmware
|
||||||
if self.receiver.status.lock_open:
|
# if self.receiver.status.lock_open:
|
||||||
# don't mess with stuff while pairing
|
# # don't mess with stuff while pairing
|
||||||
return
|
# return
|
||||||
|
#
|
||||||
self.receiver.status.poll(timestamp)
|
# self.receiver.status.poll(timestamp)
|
||||||
|
#
|
||||||
# Iterating directly through the reciver would unnecessarily probe
|
# # Iterating directly through the reciver would unnecessarily probe
|
||||||
# all possible devices, even unpaired ones.
|
# # all possible devices, even unpaired ones.
|
||||||
# Checking for each device number in turn makes sure only already
|
# # Checking for each device number in turn makes sure only already
|
||||||
# known devices are polled.
|
# # known devices are polled.
|
||||||
# This is okay because we should have already known about them all
|
# # This is okay because we should have already known about them all
|
||||||
# long before the first poll() happents, through notifications.
|
# # long before the first poll() happents, through notifications.
|
||||||
for number in range(1, 6):
|
# for number in range(1, 6):
|
||||||
if number in self.receiver:
|
# if number in self.receiver:
|
||||||
dev = self.receiver[number]
|
# dev = self.receiver[number]
|
||||||
if dev and dev.status is not None:
|
# if dev and dev.status is not None:
|
||||||
dev.status.poll(timestamp)
|
# dev.status.poll(timestamp)
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
_log.exception("polling", e)
|
# _log.exception("polling", e)
|
||||||
|
|
||||||
def _status_changed(self, device, alert=_status.ALERT.NONE, reason=None):
|
def _status_changed(self, device, alert=_status.ALERT.NONE, reason=None):
|
||||||
assert device is not None
|
assert device is not None
|
||||||
|
|
Loading…
Reference in New Issue