✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ beluga.o2switch.net ​🇻​♯➤ 4.18.0-553.123.2.lve.el8.x86_64 #1 SMP 🇾​♯➤ 2026

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 185.154.139.77 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.216.254
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗙𝗙 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ 𝗔𝗟𝗟 𝗪𝗢𝗥𝗞𝗜𝗡𝗚....

𝗛𝗢𝗠𝗘
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /opt/alt/python37/lib64/python3.7/site-packages/twisted/python//threadpool.py
# -*- test-case-name: twisted.test.test_threadpool -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
twisted.python.threadpool: a pool of threads to which we dispatch tasks.

In most cases you can just use C{reactor.callInThread} and friends
instead of creating a thread pool directly.
"""

from __future__ import division, absolute_import

import threading

from twisted._threads import pool as _pool
from twisted.python import log, context
from twisted.python.failure import Failure
from twisted.python._oldstyle import _oldStyle


WorkerStop = object()



@_oldStyle
class ThreadPool:
    """
    This class (hopefully) generalizes the functionality of a pool of threads
    to which work can be dispatched.

    L{callInThread} and L{stop} should only be called from a single thread.

    @ivar started: Whether or not the thread pool is currently running.
    @type started: L{bool}

    @ivar threads: List of workers currently running in this thread pool.
    @type threads: L{list}

    @ivar _pool: A hook for testing.
    @type _pool: callable compatible with L{_pool}
    """
    min = 5
    max = 20
    joined = False
    started = False
    workers = 0
    name = None

    threadFactory = threading.Thread
    currentThread = staticmethod(threading.currentThread)
    _pool = staticmethod(_pool)

    def __init__(self, minthreads=5, maxthreads=20, name=None):
        """
        Create a new threadpool.

        @param minthreads: minimum number of threads in the pool
        @type minthreads: L{int}

        @param maxthreads: maximum number of threads in the pool
        @type maxthreads: L{int}

        @param name: The name to give this threadpool; visible in log messages.
        @type name: native L{str}
        """
        assert minthreads >= 0, 'minimum is negative'
        assert minthreads <= maxthreads, 'minimum is greater than maximum'
        self.min = minthreads
        self.max = maxthreads
        self.name = name
        self.threads = []

        def trackingThreadFactory(*a, **kw):
            thread = self.threadFactory(*a, name=self._generateName(), **kw)
            self.threads.append(thread)
            return thread

        def currentLimit():
            if not self.started:
                return 0
            return self.max

        self._team = self._pool(currentLimit, trackingThreadFactory)


    @property
    def workers(self):
        """
        For legacy compatibility purposes, return a total number of workers.

        @return: the current number of workers, both idle and busy (but not
            those that have been quit by L{ThreadPool.adjustPoolsize})
        @rtype: L{int}
        """
        stats = self._team.statistics()
        return stats.idleWorkerCount + stats.busyWorkerCount


    @property
    def working(self):
        """
        For legacy compatibility purposes, return the number of busy workers as
        expressed by a list the length of that number.

        @return: the number of workers currently processing a work item.
        @rtype: L{list} of L{None}
        """
        return [None] * self._team.statistics().busyWorkerCount


    @property
    def waiters(self):
        """
        For legacy compatibility purposes, return the number of idle workers as
        expressed by a list the length of that number.

        @return: the number of workers currently alive (with an allocated
            thread) but waiting for new work.
        @rtype: L{list} of L{None}
        """
        return [None] * self._team.statistics().idleWorkerCount


    @property
    def _queue(self):
        """
        For legacy compatibility purposes, return an object with a C{qsize}
        method that indicates the amount of work not yet allocated to a worker.

        @return: an object with a C{qsize} method.
        """
        class NotAQueue(object):
            def qsize(q):
                """
                Pretend to be a Python threading Queue and return the
                number of as-yet-unconsumed tasks.

                @return: the amount of backlogged work not yet dispatched to a
                    worker.
                @rtype: L{int}
                """
                return self._team.statistics().backloggedWorkCount
        return NotAQueue()

    q = _queue                  # Yes, twistedchecker, I want a single-letter
                                # attribute name.


    def start(self):
        """
        Start the threadpool.
        """
        self.joined = False
        self.started = True
        # Start some threads.
        self.adjustPoolsize()
        backlog = self._team.statistics().backloggedWorkCount
        if backlog:
            self._team.grow(backlog)


    def startAWorker(self):
        """
        Increase the number of available workers for the thread pool by 1, up
        to the maximum allowed by L{ThreadPool.max}.
        """
        self._team.grow(1)


    def _generateName(self):
        """
        Generate a name for a new pool thread.

        @return: A distinctive name for the thread.
        @rtype: native L{str}
        """
        return "PoolThread-%s-%s" % (self.name or id(self), self.workers)


    def stopAWorker(self):
        """
        Decrease the number of available workers by 1, by quitting one as soon
        as it's idle.
        """
        self._team.shrink(1)


    def __setstate__(self, state):
        setattr(self, "__dict__", state)
        ThreadPool.__init__(self, self.min, self.max)


    def __getstate__(self):
        state = {}
        state['min'] = self.min
        state['max'] = self.max
        return state


    def callInThread(self, func, *args, **kw):
        """
        Call a callable object in a separate thread.

        @param func: callable object to be called in separate thread

        @param args: positional arguments to be passed to C{func}

        @param kw: keyword args to be passed to C{func}
        """
        self.callInThreadWithCallback(None, func, *args, **kw)


    def callInThreadWithCallback(self, onResult, func, *args, **kw):
        """
        Call a callable object in a separate thread and call C{onResult} with
        the return value, or a L{twisted.python.failure.Failure} if the
        callable raises an exception.

        The callable is allowed to block, but the C{onResult} function must not
        block and should perform as little work as possible.

        A typical action for C{onResult} for a threadpool used with a Twisted
        reactor would be to schedule a L{twisted.internet.defer.Deferred} to
        fire in the main reactor thread using C{.callFromThread}.  Note that
        C{onResult} is called inside the separate thread, not inside the
        reactor thread.

        @param onResult: a callable with the signature C{(success, result)}.
            If the callable returns normally, C{onResult} is called with
            C{(True, result)} where C{result} is the return value of the
            callable.  If the callable throws an exception, C{onResult} is
            called with C{(False, failure)}.

            Optionally, C{onResult} may be L{None}, in which case it is not
            called at all.

        @param func: callable object to be called in separate thread

        @param args: positional arguments to be passed to C{func}

        @param kw: keyword arguments to be passed to C{func}
        """
        if self.joined:
            return
        ctx = context.theContextTracker.currentContext().contexts[-1]

        def inContext():
            try:
                result = inContext.theWork()
                ok = True
            except:
                result = Failure()
                ok = False

            inContext.theWork = None
            if inContext.onResult is not None:
                inContext.onResult(ok, result)
                inContext.onResult = None
            elif not ok:
                log.err(result)

        # Avoid closing over func, ctx, args, kw so that we can carefully
        # manage their lifecycle.  See
        # test_threadCreationArgumentsCallInThreadWithCallback.
        inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
        inContext.onResult = onResult

        self._team.do(inContext)


    def stop(self):
        """
        Shutdown the threads in the threadpool.
        """
        self.joined = True
        self.started = False
        self._team.quit()
        for thread in self.threads:
            thread.join()


    def adjustPoolsize(self, minthreads=None, maxthreads=None):
        """
        Adjust the number of available threads by setting C{min} and C{max} to
        new values.

        @param minthreads: The new value for L{ThreadPool.min}.

        @param maxthreads: The new value for L{ThreadPool.max}.
        """
        if minthreads is None:
            minthreads = self.min
        if maxthreads is None:
            maxthreads = self.max

        assert minthreads >= 0, 'minimum is negative'
        assert minthreads <= maxthreads, 'minimum is greater than maximum'

        self.min = minthreads
        self.max = maxthreads
        if not self.started:
            return

        # Kill of some threads if we have too many.
        if self.workers > self.max:
            self._team.shrink(self.workers - self.max)
        # Start some threads if we have too few.
        if self.workers < self.min:
            self._team.grow(self.min - self.workers)


    def dumpStats(self):
        """
        Dump some plain-text informational messages to the log about the state
        of this L{ThreadPool}.
        """
        log.msg('waiters: %s' % (self.waiters,))
        log.msg('workers: %s' % (self.working,))
        log.msg('total: %s'   % (self.threads,))


Current_dir [ 𝗡𝗢𝗧 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
1 Jan 1970 12.00 AM
root / root
0
__pycache__
--
25 Jul 2024 8.43 AM
root / linksafe
0755
_pydoctortemplates
--
25 Jul 2024 8.43 AM
root / linksafe
0755
test
--
25 Jul 2024 8.43 AM
root / linksafe
0755
__init__.py
0.658 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
_appdirs.py
0.77 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
_inotify.py
3.374 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
_oldstyle.py
2.532 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
_release.py
18.34 KB
18 Mar 2020 8.27 AM
root / linksafe
0644
_setup.py
13.946 KB
8 Mar 2020 10.44 AM
root / linksafe
0644
_shellcomp.py
24.248 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
_textattributes.py
8.866 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
_tzhelper.py
3.117 KB
26 May 2019 5.43 AM
root / linksafe
0644
_url.py
0.247 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
compat.py
23.196 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
components.py
13.92 KB
8 Mar 2020 10.44 AM
root / linksafe
0644
constants.py
0.531 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
context.py
3.93 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
deprecate.py
26.316 KB
18 Dec 2019 3.37 AM
root / linksafe
0644
failure.py
26.918 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
fakepwd.py
5.994 KB
26 May 2019 5.43 AM
root / linksafe
0644
filepath.py
57.507 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
formmethod.py
11.191 KB
26 May 2019 5.43 AM
root / linksafe
0644
htmlizer.py
3.458 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
lockfile.py
7.537 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
log.py
21.945 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
logfile.py
9.847 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
modules.py
26.505 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
monkey.py
2.175 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
procutils.py
1.386 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
randbytes.py
3.866 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
rebuild.py
9.051 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
reflect.py
19.021 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
release.py
1.164 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
roots.py
7.23 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
runtime.py
6.07 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
sendmsg.py
3.34 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
shortcut.py
2.2 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
syslog.py
3.643 KB
26 May 2019 5.43 AM
root / linksafe
0644
systemd.py
2.768 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
text.py
5.354 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
threadable.py
3.22 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
threadpool.py
9.609 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
twisted-completion.zsh
1.339 KB
15 Jun 2019 9.59 PM
root / linksafe
0644
url.py
0.238 KB
26 May 2019 5.43 AM
root / linksafe
0644
urlpath.py
8.871 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
usage.py
34.182 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
util.py
27.276 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
versions.py
0.314 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
win32.py
4.216 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
zippath.py
9.021 KB
18 Dec 2019 3.08 AM
root / linksafe
0644
zipstream.py
9.528 KB
18 Dec 2019 3.08 AM
root / linksafe
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF