File manager - Edit - /home/newsbmcs.com/public_html/static/img/logo/_threads.tar
Back
_pool.py 0000644 00000004334 15030470614 0006232 0 ustar 00 # -*- test-case-name: twisted._threads.test -*- # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Top level thread pool interface, used to implement L{twisted.python.threadpool}. """ from queue import Queue from threading import Lock, Thread, local as LocalStorage from twisted.python.log import err from ._team import Team from ._threadworker import LockWorker, ThreadWorker def pool(currentLimit, threadFactory=Thread): """ Construct a L{Team} that spawns threads as a thread pool, with the given limiting function. @note: Future maintainers: while the public API for the eventual move to twisted.threads should look I{something} like this, and while this function is necessary to implement the API described by L{twisted.python.threadpool}, I am starting to think the idea of a hard upper limit on threadpool size is just bad (turning memory performance issues into correctness issues well before we run into memory pressure), and instead we should build something with reactor integration for slowly releasing idle threads when they're not needed and I{rate} limiting the creation of new threads rather than just hard-capping it. @param currentLimit: a callable that returns the current limit on the number of workers that the returned L{Team} should create; if it already has more workers than that value, no new workers will be created. @type currentLimit: 0-argument callable returning L{int} @param threadFactory: Factory that, when given a C{target} keyword argument, returns a L{threading.Thread} that will run that target. @type threadFactory: callable returning a L{threading.Thread} @return: a new L{Team}. """ def startThread(target): return threadFactory(target=target).start() def limitedWorkerCreator(): stats = team.statistics() if stats.busyWorkerCount + stats.idleWorkerCount >= currentLimit(): return None return ThreadWorker(startThread, Queue()) team = Team( coordinator=LockWorker(Lock(), LocalStorage()), createWorker=limitedWorkerCreator, logException=err, ) return team __pycache__/_threadworker.cpython-310.pyc 0000644 00000007050 15030470614 0014317 0 ustar 00 o �b� � @ s^ d Z ddlmZ ddlmZ ddlmZ e� Zee�G dd� d��Z ee�G dd � d ��Z d S )zE Implementation of an L{IWorker} based on native threads and queues. � )�implementer� )�Quit)�IExclusiveWorkerc @ �( e Zd ZdZdd� Zdd� Zdd� ZdS ) �ThreadWorkerz� An L{IExclusiveWorker} implemented based on a single thread and a queue. This worker ensures exclusivity (i.e. it is an L{IExclusiveWorker} and not an L{IWorker}) by performing all of the work passed to C{do} on the I{same} thread. c s&