trequestpool.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:stig 作者: rndusr 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号