403Webshell
Server IP : 123.56.80.60  /  Your IP : 216.73.216.78
Web Server : Apache/2.4.54 (Win32) OpenSSL/1.1.1s PHP/7.4.33 mod_fcgid/2.3.10-dev
System : Windows NT iZhx3sob14hnz7Z 10.0 build 14393 (Windows Server 2016) i586
User : SYSTEM ( 0)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/Program Files (x86)/Alibaba/Aegis/PythonLoaderTemp/third_party/oss2/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : C:/Program Files (x86)/Alibaba/Aegis/PythonLoaderTemp/third_party/oss2/task_queue.py
# -*- coding: utf-8 -*-

import threading
import sys
import logging

try:
    import Queue as queue
except ImportError:
    import queue

import traceback


class TaskQueue(object):
    def __init__(self, producer, consumers):
        self.__producer = producer
        self.__consumers = consumers

        self.__threads = []

        # must be an infinite queue, otherwise producer may be blocked after all consumers being dead.
        self.__queue = queue.Queue()

        self.__lock = threading.Lock()
        self.__exc_info = None
        self.__exc_stack = ''

    def run(self):
        self.__add_and_run(threading.Thread(target=self.__producer_func))

        for c in self.__consumers:
            self.__add_and_run(threading.Thread(target=self.__consumer_func, args=(c,)))

        # give KeyboardInterrupt chances to happen by joining with timeouts.
        while self.__any_active():
            for t in self.__threads:
                t.join(1)

        if self.__exc_info:
            logging.debug('An exception was thrown by producer or consumer, backtrace: {0}'.format(self.__exc_stack))
            raise self.__exc_info[1]

    def put(self, data):
        assert data is not None
        self.__queue.put(data)

    def get(self):
        return self.__queue.get()

    def ok(self):
        with self.__lock:
            return self.__exc_info is None

    def __add_and_run(self, thread):
        thread.daemon = True
        thread.start()
        self.__threads.append(thread)

    def __any_active(self):
        return any(t.is_alive() for t in self.__threads)

    def __producer_func(self):
        try:
            self.__producer(self)
        except:
            self.__on_exception(sys.exc_info())
            self.__put_end()
        else:
            self.__put_end()

    def __consumer_func(self, consumer):
        try:
            consumer(self)
        except:
            self.__on_exception(sys.exc_info())

    def __put_end(self):
        for i in range(len(self.__consumers)):
            self.__queue.put(None)

    def __on_exception(self, exc_info):
        with self.__lock:
            if self.__exc_info is None:
                self.__exc_info = exc_info
                self.__exc_stack = traceback.format_exc()




Youez - 2016 - github.com/yon3zu
LinuXploit