def totalSize(): size = 0 for thread in threadingEnumerate(): if thread.isAlive() and hasattr(thread, 'downloadQueue'): size += thread.downloadQueue.qsize() + len( thread.downloadQueue.pending) return size
def add(self, objectHash = None): with self.lock: # add a new object into existing thread lists if objectHash: if objectHash not in self.hashes: self.hashes[objectHash] = {'created': time.time(), 'sendCount': 0, 'peers': []} for thread in threadingEnumerate(): if thread.isAlive() and hasattr(thread, 'peer') and \ thread.peer not in self.hashes[objectHash]['peers']: self.hashes[objectHash]['peers'].append(thread.peer) # add all objects into the current thread else: for objectHash in self.hashes: if current_thread().peer not in self.hashes[objectHash]['peers']: self.hashes[objectHash]['peers'].append(current_thread().peer)
def stop(): for thread in threadingEnumerate(): if thread.isAlive() and hasattr(thread, 'downloadQueue'): thread.downloadQueue.stopped = True with thread.downloadQueue.lock: thread.downloadQueue.pending = {}
def totalSize(): size = 0 for thread in threadingEnumerate(): if thread.isAlive() and hasattr(thread, 'downloadQueue'): size += thread.downloadQueue.qsize() + len(thread.downloadQueue.pending) return size