當前位置: 首頁>>代碼示例>>Python>>正文


Python threading.Event方法代碼示例

本文整理匯總了Python中threading.Event方法的典型用法代碼示例。如果您正苦於以下問題:Python threading.Event方法的具體用法?Python threading.Event怎麽用?Python threading.Event使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在threading的用法示例。


在下文中一共展示了threading.Event方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: auto

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def auto(self, start_message, end_message):
        """
        Auto progress.
        """
        self._auto_running = threading.Event()
        self._auto_thread = threading.Thread(target=self._spin)

        self.start(start_message)
        self._auto_thread.start()

        try:
            yield self
        except (Exception, KeyboardInterrupt):
            self._io.write_line("")

            self._auto_running.set()
            self._auto_thread.join()

            raise

        self.finish(end_message, reset_indicator=True) 
開發者ID:sdispater,項目名稱:clikit,代碼行數:23,代碼來源:progress_indicator.py

示例2: __sats

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def __sats(self, data):
        message = int(data[1])
        messages = int(data[1])
        viewed = int(data[3])

        if message == 1:
            self._sats.clear()

        blocks = (len(data) - 4) / 4
        for i in range(0, blocks):
            sat = int(data[4 + i * 4])
            level = data[7 + i * 4]
            used = True
            if level == '':
                level = None
                used = False
            else:
                level = int(level)
            self._sats[sat] = {'Level': level,
                               'Used': used}

        if message == messages and len(self._sats) == viewed:
            event = Event(Events.GPS_SATS, sats=self._sats)
            post_event(self._eventHandler, event) 
開發者ID:EarToEarOak,項目名稱:RF-Monitor,代碼行數:26,代碼來源:gps.py

示例3: __read

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def __read(self):
        for resp in self.__serial_read():
            nmea = resp.split('*')
            if len(nmea) == 2:
                data = nmea[0].split(',')
                if data[0] in ['GPGGA', 'GPGSV']:
                    checksum = self.__checksum(nmea[0])
                    if checksum == nmea[1]:
                        if data[0] == 'GPGGA':
                            self.__global_fix(data)
                        elif data[0] == 'GPGSV':
                            self.__sats(data)
                    else:
                        warn = 'Invalid checksum for {} sentence'.format(data[0])
                        event = Event(Events.GPS_WARN, msg=warn)
                        post_event(self._eventHandler, event) 
開發者ID:EarToEarOak,項目名稱:RF-Monitor,代碼行數:18,代碼來源:gps.py

示例4: test_blockscope

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def test_blockscope():
    class dummy_block(object):
        def __init__(self, prefix):
            self.prefix = prefix
            self._empty_prefix = False
    blockscope_list = []
    status = [False]
    event = threading.Event()
    def f():
        with block._BlockScope(dummy_block("spawned_")):
            x= NameManager.current.get(None, "hello")
            event.wait()
            if x == "spawned_hello0":
                status[0] = True
    thread = threading.Thread(target=f)
    thread.start()
    block._BlockScope.create("main_thread", None, "hi")
    event.set()
    thread.join()
    event.clear()
    assert status[0], "Spawned thread isn't using the correct blockscope namemanager" 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:23,代碼來源:test_thread_local.py

示例5: __init__

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def __init__(self, open):
        """
        A class that encapsulates a FileSystemWatcher over SMB. It is designed to make it easy to run the watcher in
        the background and provide an event that is fired when the server notifies that a change has occurred. It is
        up to the caller to action on that event through their own sync or asynchronous implementation.

        :param open: The Open() class of a directory to watch for change notifications.
        """
        self.open = open
        self.response_event = threading.Event()

        self._t_on_response = threading.Thread(target=self._on_response)
        self._t_on_response.daemon = True
        self._t_exc = None
        self._request = None
        self._file_actions = None
        self._result_lock = threading.Lock()  # Used to ensure the result is only processed once 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:19,代碼來源:change_notify.py

示例6: test_create_task

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def test_create_task(app):
    e = Event()

    async def coro():
        await asyncio.sleep(0.05)
        e.set()

    app.add_task(coro)

    @app.route("/early")
    def not_set(request):
        return text(str(e.is_set()))

    @app.route("/late")
    async def set(request):
        await asyncio.sleep(0.1)
        return text(str(e.is_set()))

    request, response = app.test_client.get("/early")
    assert response.body == b"False"

    request, response = app.test_client.get("/late")
    assert response.body == b"True" 
開發者ID:huge-success,項目名稱:sanic,代碼行數:25,代碼來源:test_create_task.py

示例7: send_response

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def send_response(self, stream_id, headers):
        """
        Thread-safe method called from outside the main asyncio thread in order
        to send the HTTP response headers on behalf of a WSGI application.

        Returns a threading event that will fire when the headers have been
        emitted to the network.
        """
        event = threading.Event()

        def _inner_send(stream_id, headers, event):
            self.conn.send_headers(stream_id, headers, end_stream=False)
            self.transport.write(self.conn.data_to_send())
            event.set()

        self._loop.call_soon_threadsafe(
            _inner_send,
            stream_id,
            headers,
            event
        )
        return event 
開發者ID:python-hyper,項目名稱:hyper-h2,代碼行數:24,代碼來源:wsgi-server.py

示例8: reset_state

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def reset_state(self):
        super(MultiThreadMapData, self).reset_state()
        if self._threads:
            self._threads[0].stop()
            for t in self._threads:
                t.join()

        self._in_queue = queue.Queue()
        self._out_queue = queue.Queue()
        self._evt = threading.Event()
        self._threads = [MultiThreadMapData._Worker(
            self._in_queue, self._out_queue, self._evt, self.map_func)
            for _ in range(self.num_thread)]
        for t in self._threads:
            t.start()

        self._guard = DataFlowReentrantGuard()

        # Call once at the beginning, to ensure inq+outq has a total of buffer_size elements
        self._fill_buffer() 
開發者ID:tensorpack,項目名稱:dataflow,代碼行數:22,代碼來源:parallel_map.py

示例9: __init__

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def __init__(self, app, reportrate=1):
        self.app = app
        self.proto = None
        self.timer = None
        self._fragment = None
        self.abort_stream = False
        self.pause_stream = False  # asyncio.Event()
        self.okcnt = None
        self.ping_pong = True  # ping pong protocol for streaming
        self.file_streamer = None
        self.report_rate = reportrate
        self._reroute_incoming_data_to = None
        self._restart_timer = False
        self.is_streaming = False
        self.do_query = False
        self.last_tool = None
        self.is_suspend = False
        self.m0 = None
        self.net_connection = False
        self.log = logging.getLogger()  # .getChild('Comms')
        # logging.getLogger().setLevel(logging.DEBUG) 
開發者ID:wolfmanjm,項目名稱:kivy-smoothie-host,代碼行數:23,代碼來源:comms.py

示例10: __init__

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def __init__( self ):
      """Initialize variables and setup server"""
      
      HOST = ""
      PORT = 5000

      self.board = []
      self.currentPlayer = 0
      self.turnCondition = threading.Condition()
      self.gameBeginEvent = threading.Event()

      for i in range( 9 ):
         self.board.append( None )

      # setup server socket
      self.server = socket.socket( socket.AF_INET,
         socket.SOCK_STREAM )
      self.server.bind( ( HOST, PORT ) )
      self.display( "Server awaiting connections..." ) 
開發者ID:PythonClassRoom,項目名稱:PythonClassBook,代碼行數:21,代碼來源:fig20_06.py

示例11: __init__

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def __init__(self, request, context, checkpoint_mgr, proxy=None):
        """
        Constructs a `Job` with properties request, context and a
         optional proxy setting.
        :param request: A `Request` instance which contains request settings.
        :param context: A values set contains initial values for template
         variables.
        :param proxy: A optional `Proxy` object contains proxy related
         settings.
        """
        self._request = request
        self._context = context
        self._checkpoint_mgr = checkpoint_mgr
        self._client = HttpClient(proxy)
        self._stopped = True
        self._should_stop = False

        self._request_iterated_count = 0
        self._iteration_mode = self._request.iteration_mode
        self._max_iteration_count = self._get_max_iteration_count()

        self._running_thread = None
        self._terminated = threading.Event() 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:25,代碼來源:engine.py

示例12: test_add_callback_while_closing

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def test_add_callback_while_closing(self):
        # Issue #635: add_callback() should raise a clean exception
        # if called while another thread is closing the IOLoop.
        closing = threading.Event()

        def target():
            other_ioloop.add_callback(other_ioloop.stop)
            other_ioloop.start()
            closing.set()
            other_ioloop.close(all_fds=True)
        other_ioloop = IOLoop()
        thread = threading.Thread(target=target)
        thread.start()
        closing.wait()
        for i in range(1000):
            try:
                other_ioloop.add_callback(lambda: None)
            except RuntimeError as e:
                self.assertEqual("IOLoop is closing", str(e))
                break 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:22,代碼來源:ioloop_test.py

示例13: __init__

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def __init__(self, job_id):
        self.samples = []
        self.status = self.STATUS_CREATED
        self.thread = None
        self.finished = Event()
        self.status_lock = Lock()
        self.id = job_id 
開發者ID:Cisco-Talos,項目名稱:BASS,代碼行數:9,代碼來源:core.py

示例14: __timeout

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def __timeout(self):
        self.stop()
        event = Event(Events.GPS_TIMEOUT, msg='GPS timeout')
        post_event(self._eventHandler, event) 
開發者ID:EarToEarOak,項目名稱:RF-Monitor,代碼行數:6,代碼來源:gps.py

示例15: __global_fix

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import Event [as 別名]
def __global_fix(self, data):
        if data[6] in ['1', '2']:
            lat = self.__coord(data[2], data[3])
            lon = self.__coord(data[4], data[5])

            event = Event(Events.GPS_LOC, loc=(lat, lon))
            post_event(self._eventHandler, event) 
開發者ID:EarToEarOak,項目名稱:RF-Monitor,代碼行數:9,代碼來源:gps.py


注:本文中的threading.Event方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。