commented-out the poll-ticking feature

not useful right now, and less code to worry about
This commit is contained in:
Daniel Pavel 2013-07-06 14:23:56 +02:00
parent faa6de3b75
commit 508444526a
2 changed files with 54 additions and 54 deletions

View File

@ -5,7 +5,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals
import threading as _threading
from time import time as _timestamp
# from time import time as _timestamp
# for both Python 2 and 3
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.
# 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):
@ -126,7 +126,7 @@ class EventsListener(_threading.Thread):
self._queued_notifications = _Queue(16)
self._notifications_callback = notifications_callback
self.tick_period = 0
# self.tick_period = 0
def run(self):
self._active = True
@ -139,10 +139,10 @@ class EventsListener(_threading.Thread):
self.has_started()
last_tick = 0
# last_tick = 0
# the first idle read -- delay it a bit, and make sure to stagger
# idle reads for multiple receivers
idle_reads = _IDLE_READS + (ihandle % 5) * 2
# idle_reads = _IDLE_READS + (ihandle % 5) * 2
while self._active:
if self._queued_notifications.empty():
@ -168,14 +168,14 @@ class EventsListener(_threading.Thread):
except:
_log.exception("processing %s", n)
elif self.tick_period:
idle_reads -= 1
if idle_reads <= 0:
idle_reads = _IDLE_READS
now = _timestamp()
if now - last_tick >= self.tick_period:
last_tick = now
self.tick(now)
# elif self.tick_period:
# idle_reads -= 1
# if idle_reads <= 0:
# idle_reads = _IDLE_READS
# now = _timestamp()
# if now - last_tick >= self.tick_period:
# last_tick = now
# self.tick(now)
del self._queued_notifications
self.has_stopped()
@ -193,9 +193,9 @@ class EventsListener(_threading.Thread):
"""Called right before the thread stops."""
pass
def tick(self, timestamp):
"""Called about every tick_period seconds."""
pass
# def tick(self, timestamp):
# """Called about every tick_period seconds."""
# pass
def _notifications_hook(self, n):
# Only consider unhandled notifications that were sent from this thread,

View File

@ -39,7 +39,7 @@ def _ghost(device):
# how often to poll devices that haven't updated their statuses on their own
# (through notifications)
_POLL_TICK = 5 * 60 # seconds
# _POLL_TICK = 5 * 60 # seconds
class ReceiverListener(_listener.EventsListener):
@ -49,7 +49,7 @@ class ReceiverListener(_listener.EventsListener):
super(ReceiverListener, self).__init__(receiver, self._notifications_handler)
# no reason to enable polling yet
# self.tick_period = _POLL_TICK
self._last_tick = 0
# self._last_tick = 0
assert 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)
self.status_changed_callback(r) #, _status.ALERT.NOTIFICATION)
def tick(self, timestamp):
if not self.tick_period:
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
# 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
# # sleep, and we have to reinitialize the receiver again
# _log.warn("%s: possible sleep detected, closing this listener", self.receiver)
# self.stop()
# def tick(self, timestamp):
# if not self.tick_period:
# 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
# # 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
# # # sleep, and we have to reinitialize the receiver again
# # _log.warn("%s: possible sleep detected, closing this listener", self.receiver)
# # self.stop()
# # return
#
# self._last_tick = timestamp
#
# try:
# # read these in case they haven't been read already
# # self.receiver.serial, self.receiver.firmware
# if self.receiver.status.lock_open:
# # don't mess with stuff while pairing
# return
self._last_tick = timestamp
try:
# read these in case they haven't been read already
# self.receiver.serial, self.receiver.firmware
if self.receiver.status.lock_open:
# don't mess with stuff while pairing
return
self.receiver.status.poll(timestamp)
# Iterating directly through the reciver would unnecessarily probe
# all possible devices, even unpaired ones.
# Checking for each device number in turn makes sure only already
# known devices are polled.
# This is okay because we should have already known about them all
# long before the first poll() happents, through notifications.
for number in range(1, 6):
if number in self.receiver:
dev = self.receiver[number]
if dev and dev.status is not None:
dev.status.poll(timestamp)
except Exception as e:
_log.exception("polling", e)
#
# self.receiver.status.poll(timestamp)
#
# # Iterating directly through the reciver would unnecessarily probe
# # all possible devices, even unpaired ones.
# # Checking for each device number in turn makes sure only already
# # known devices are polled.
# # This is okay because we should have already known about them all
# # long before the first poll() happents, through notifications.
# for number in range(1, 6):
# if number in self.receiver:
# dev = self.receiver[number]
# if dev and dev.status is not None:
# dev.status.poll(timestamp)
# except Exception as e:
# _log.exception("polling", e)
def _status_changed(self, device, alert=_status.ALERT.NONE, reason=None):
assert device is not None