def register(self, sid, callback, keys=(), tfilter=None):
"""Add new request to request pool
sid: Subscriber ID (any hashable)
callback: Callable that receives a tuple of Torrents on updates
keys: Wanted Torrent keys
tfilter: None for all torrents or TorrentFilter instance
"""
if isinstance(tfilter, abc.Sequence):
tfilter = TorrentFilter('|'.join('id=%s' % tid for tid in tfilter))
log.debug('Registering subscriber: %s', sid)
event = blinker.signal(sid)
event.connect(callback)
self._keys[event] = tuple(keys)
self._tfilters[event] = tfilter
# It's possible that a currently ongoing request doesn't collect the
# keys this new callback needs. In that case, the request is finished
# AFTER we added the callback, and the callback would be called with
# lacking keys, resuling in a KeyError.
# Therefore we ask the poller to dump the result of a currently
# ongoing request to prevent this.
if self.running:
self.skip_ongoing_request()
self._combine_requests()
评论列表
文章目录