当前位置: 首页>>代码示例>>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;未经允许,请勿转载。