python类Condition()的实例源码

WxNeteaseMusic.py 文件源码 项目:WxNeteaseMusic 作者: yaphone 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
        self.help_msg = \
            u"H: ????\n" \
            u"L: ???????\n" \
            u"M: ????\n" \
            u"N: ???\n"\
            u"U: ????\n"\
            u"R: ????\n"\
            u"S: ????\n"\
            u"T: ????\n"\
            u"G: ????\n"\
            u"E: ??\n"
        self.con = threading.Condition()
        self.myNetease = MyNetease()
        self.playlist = self.myNetease.get_top_songlist()  #???????
        self.mp3 = None
        t = threading.Thread(target=self.play)
        t.start()
test_client.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_thread_safe(self):
        thread_count = 4
        repeats = 1000

        latch = [threading.Condition(), thread_count]

        def thread_main(latch):
            for _ in range(repeats):
                self.assertEqual("False", self.conn.test_service.bool_to_string(False))
                self.assertEqual(12345, self.conn.test_service.string_to_int32("12345"))
            with latch[0]:
                latch[1] -= 1
                if latch[1] <= 0:
                    latch[0].notifyAll()

        for i in range(thread_count):
            t = threading.Thread(target=thread_main, args=(latch,))
            t.daemon = True
            t.start()

        with latch[0]:
            while latch[1] > 0:
                latch[0].wait(10)
        self.assertEqual(0, latch[1]);
Queue.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, maxsize=0):
        self.maxsize = maxsize
        self._init(maxsize)
        # mutex must be held whenever the queue is mutating.  All methods
        # that acquire mutex must release it before returning.  mutex
        # is shared between the three conditions, so acquiring and
        # releasing the conditions also acquires and releases mutex.
        self.mutex = _threading.Lock()
        # Notify not_empty whenever an item is added to the queue; a
        # thread waiting to get is notified then.
        self.not_empty = _threading.Condition(self.mutex)
        # Notify not_full whenever an item is removed from the queue;
        # a thread waiting to put is notified then.
        self.not_full = _threading.Condition(self.mutex)
        # Notify all_tasks_done whenever the number of unfinished tasks
        # drops to zero; thread waiting to join() is notified to resume
        self.all_tasks_done = _threading.Condition(self.mutex)
        self.unfinished_tasks = 0
notification.py 文件源码 项目:logscan 作者: magedu 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self):
        self.message = None
        self.__event = threading.Event()
        self.__cond = threading.Condition()
        self.__mail_queue = Queue(100)
check.py 文件源码 项目:logscan 作者: magedu 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __init__(self, queue, counter):
        self.queue = queue
        self.counter = counter
        self.checkers = {}
        self.queues = {}
        self.events = {}
        self.line = None
        self.__event = threading.Event()
        self.__cond = threading.Condition()
bluefile_helpers.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 52 收藏 0 点赞 0 评论 0
def __init__(self, input_stream=None, porttype=None, rem_file=False):
        """
        Instantiates a new object responsible for writing data from the port 
        into a file.  The file name is given by the input_stream variable.

        It is important to notice that the porttype is a BULKIO__POA type and
        not a BULKIO type.  The reason is because it is used to generate a 
        Port class that will be returned when the getPort() is invoked.  The
        returned class is the one acting as a server and therefore must be a
        Portable Object Adapter rather and a simple BULKIO object.

        Inputs:
            <input_stream>    The X-Midas file to generate
            <porttype>        The BULKIO__POA data type
            <rem_file>        Removes the input_stream if present 
        """

        if input_stream != None and os.path.isfile(input_stream):
            os.remove(input_stream)

        self.port_type = porttype
        self.outFile = input_stream
        self.port_lock = threading.Lock()
        self.eos_cond = threading.Condition(self.port_lock)
        self.gotEOS = False
        self.header = None
        self.done = False
        self._firstPacket = True
io_helpers.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def waitAllPacketsSent(self, timeout=None):
        """
        Wait until all of the packets queued on this source have been pushed to
        all connected ports. If timeout is given, it should be the maximum
        number of seconds to wait before giving up.
        """
        self._packetsSentCond.acquire()
        try:
            # Assume no spurious signals will occur, so we can defer to the
            # timeout handling of Python's Condition object.
            if self._packetsPending > 0:
                self._packetsSentCond.wait(timeout)
        finally:
            self._packetsSentCond.release()
Subscriber.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self):
        self._recv_disconnect = True
        self.logger = logging.getLogger("ossie.events.Subscriber.Receiver")
        self._lock = threading.Lock()
        self._cond = threading.Condition(self._lock)
input_ports.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 59 收藏 0 点赞 0 评论 0
def __init__(self, name, logger=None, sriCompare=sri.compare, newSriCallback=None, sriChangeCallback=None,  maxsize=100, PortTransferType=_TYPE_ ):
        self.name = name
        self.logger = logger
        self.queue = collections.deque()
        self._maxSize = maxsize
        self.port_lock = threading.Lock()
        self._not_full = threading.Condition(self.port_lock)
        self._not_empty = threading.Condition(self.port_lock)
        self._breakBlock = False
        self.stats =  InStats(name, PortTransferType)
        self.blocking = False
        self.sri_cmp = sriCompare
        self.newSriCallback = newSriCallback
        self.sriChangeCallback = sriChangeCallback
        self.sriDict = {} # key=streamID, value=StreamSRI

        if logger==None:
            self.logger = logging.getLogger("redhawk.bulkio.input."+name)

        _cmpMsg  = "DEFAULT"
        _newSriMsg  = "EMPTY"
        _sriChangeMsg  = "EMPTY"
        if sriCompare != sri.compare:
            _cmpMsg  = "USER_DEFINED"
        if newSriCallback:
            _newSriMsg  = "USER_DEFINED"
        if sriChangeCallback:
            _sriChangeMsg  = "USER_DEFINED"

        if self.logger:
            self.logger.debug( "bulkio::InPort CTOR port:" + str(name) +
                          " Blocking/MaxInputQueueSize " + str(self.blocking) + "/"  + str(maxsize) +
                          " SriCompare/NewSriCallback/SriChangeCallback " +  _cmpMsg + "/" + _newSriMsg + "/" + _sriChangeMsg );
input_ports.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, name, logger=None, sriCompare=sri.compare, newSriCallback=None, sriChangeCallback=None,  maxsize=100, PortTransferType=_TYPE_ ):
        self.name = name
        self.logger = logger
        self.queue = collections.deque()
        self._maxSize = maxsize
        self.port_lock = threading.Lock()
        self._not_full = threading.Condition(self.port_lock)
        self._not_empty = threading.Condition(self.port_lock)
        self._breakBlock = False
        self.stats =  InStats(name, PortTransferType)
        self.blocking = False
        self.sri_cmp = sriCompare
        self.newSriCallback = newSriCallback
        self.sriChangeCallback = sriChangeCallback
        self.sriDict = {} # key=streamID, value=StreamSRI

        if logger==None:
            self.logger = logging.getLogger("redhawk.bulkio.input."+name)

        _cmpMsg  = "DEFAULT"
        _newSriMsg  = "EMPTY"
        _sriChangeMsg  = "EMPTY"
        if sriCompare != sri.compare:
            _cmpMsg  = "USER_DEFINED"
        if newSriCallback:
            _newSriMsg  = "USER_DEFINED"
        if sriChangeCallback:
            _sriChangeMsg  = "USER_DEFINED"

        if self.logger:
            self.logger.debug( "bulkio::InPort CTOR port:" + str(name) +
                          " Blocking/MaxInputQueueSize " + str(self.blocking) + "/"  + str(maxsize) +
                          " SriCompare/NewSriCallback/SriChangeCallback " +  _cmpMsg + "/" + _newSriMsg + "/" + _sriChangeMsg );
threaded_tcp_client.py 文件源码 项目:BitBot 作者: crack00r 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, proxy=None):
        self.connected = False
        self._proxy = proxy
        self._recreate_socket()

        # Support for multi-threading advantages and safety
        self.cancelled = Event()  # Has the read operation been cancelled?
        self.delay = 0.1  # Read delay when there was no data available
        self._lock = Lock()

        self._buffer = []
        self._read_thread = Thread(target=self._reading_thread, daemon=True)
        self._cv = Condition()  # Condition Variable
queues.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _after_fork(self):
        debug('Queue._after_fork()')
        self._notempty = threading.Condition(threading.Lock())
        self._buffer = collections.deque()
        self._thread = None
        self._jointhread = None
        self._joincancelled = False
        self._closed = False
        self._close = None
        self._send = self._writer.send
        self._recv = self._reader.recv
        self._poll = self._reader.poll
queues.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__(self, maxsize=0):
        Queue.__init__(self, maxsize)
        self._unfinished_tasks = Semaphore(0)
        self._cond = Condition()
pool.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, cache, callback):
        self._cond = threading.Condition(threading.Lock())
        self._job = job_counter.next()
        self._cache = cache
        self._ready = False
        self._callback = callback
        cache[self._job] = self
pool.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, cache):
        self._cond = threading.Condition(threading.Lock())
        self._job = job_counter.next()
        self._cache = cache
        self._items = collections.deque()
        self._index = 0
        self._length = None
        self._unsorted = {}
        cache[self._job] = self
cnn_util.py 文件源码 项目:benchmarks 作者: tensorflow 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, parties):
    """Create a barrier, initialised to 'parties' threads."""
    self.cond = threading.Condition(threading.Lock())
    self.parties = parties
    # Indicates the number of waiting parties.
    self.waiting = 0
    # generation is needed to deal with spurious wakeups. If self.cond.wait()
    # wakes up for other reasons, generation will force it go back to wait().
    self.generation = 0
    self.broken = False
thread_util.py 文件源码 项目:mongodb-monitoring 作者: jruaux 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, value=1):
        if value < 0:
            raise ValueError("semaphore initial value must be >= 0")
        self._cond = threading.Condition(threading.Lock())
        self._value = value
monitor.py 文件源码 项目:DeepSea 作者: SUSE 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, show_state_steps, show_dynamic_steps):
        super(Monitor, self).__init__()
        self._processor = SaltEventProcessor()
        self._processor.add_listener(Monitor.DeepSeaEventListener(self))
        self._show_state_steps = show_state_steps
        self._show_dynamic_steps = show_dynamic_steps
        self._running_stage = None
        self._monitor_listeners = []
        self._event_lock = threading.Lock()
        self._event_cond = threading.Condition(self._event_lock)
        self._event_buffer = []
        self._running = False
        self._stage_steps = {}
concurrent.py 文件源码 项目:deb-python-cassandra-driver 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, session, statements_and_params):
        self.session = session
        self._enum_statements = enumerate(iter(statements_and_params))
        self._condition = Condition()
        self._fail_fast = False
        self._results_queue = []
        self._current = 0
        self._exec_count = 0
        self._exec_depth = 0
fcgi_base.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, conn):
        super(MultiplexedInputStream, self).__init__(conn)

        # Arbitrates access to this InputStream (it's used simultaneously
        # by a Request and its owning Connection object).
        lock = threading.RLock()

        # Notifies Request thread that there is new data available.
        self._lock = threading.Condition(lock)


问题


面经


文章

微信
公众号

扫码关注公众号