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


Python Thread.start方法代碼示例

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


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

示例1: filter_by_tag

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def filter_by_tag(self, tag):
        """
        Filter incoming events by the given ``tag``.

        ``tag`` is a byte or unicode string with the name of a tag.  Only
        events for devices which have this tag attached pass the filter and are
        handed to the caller.

        Like with :meth:`filter_by` this filter is also executed inside the
        kernel, so that client processes are usually not woken up for devices
        without the given ``tag``.

        .. udevversion:: 154

        .. versionadded:: 0.9

        .. versionchanged:: 0.15
           This method can also be after :meth:`start()` now.
        """
        self._libudev.udev_monitor_filter_add_match_tag(
            self, ensure_byte_string(tag))
        self._libudev.udev_monitor_filter_update(self) 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:24,代碼來源:monitor.py

示例2: enable_receiving

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def enable_receiving(self):
        """
        Switch the monitor into listing mode.

        Connect to the event source and receive incoming events.  Only after
        calling this method, the monitor listens for incoming events.

        .. note::

           This method is implicitly called by :meth:`__iter__`.  You don't
           need to call it explicitly, if you are iterating over the
           monitor.

        .. deprecated:: 0.16
           Will be removed in 1.0. Use :meth:`start()` instead.
        """
        import warnings
        warnings.warn('Will be removed in 1.0. Use Monitor.start() instead.',
                      DeprecationWarning)
        self.start() 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:22,代碼來源:monitor.py

示例3: start

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def start(self):
        """
        Start this monitor.

        The monitor will not receive events until this method is called. This
        method does nothing if called on an already started :class:`Monitor`.

        .. note::

           Typically you don't need to call this method. It is implicitly
           called by :meth:`poll()` and :meth:`__iter__()`.

        .. seealso:: :attr:`started`
        .. versionchanged:: 0.16
           This method does nothing if the :class:`Monitor` was already
           started.
        """
        if not self._started:
            self._libudev.udev_monitor_enable_receiving(self)
            # Force monitor FD into non-blocking mode
            pipe.set_fd_status_flag(self, os.O_NONBLOCK)
            self._started = True 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:24,代碼來源:monitor.py

示例4: run

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def run(self):
        self.monitor.start()
        notifier = poll.Poll.for_events(
            (self.monitor, 'r'), (self._stop_event.source, 'r'))
        while True:
            for file_descriptor, event in eintr_retry_call(notifier.poll):
                if file_descriptor == self._stop_event.source.fileno():
                    # in case of a stop event, close our pipe side, and
                    # return from the thread
                    self._stop_event.source.close()
                    return
                elif file_descriptor == self.monitor.fileno() and event == 'r':
                    read_device = partial(eintr_retry_call, self.monitor.poll, timeout=0)
                    for device in iter(read_device, None):
                        self._callback(device)
                else:
                    raise EnvironmentError('Observed monitor hung up') 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:19,代碼來源:monitor.py

示例5: process_packet

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def process_packet(self, ident, code, data, flags):
        """
        Handle packets from VM
        """
        # reply pkt shows only once
        if flags == REPLY_PACKET_TYPE:
            chan = self.reply_pkt_map.get(ident)
            if not chan:
                return
            return chan.put((ident, code, data))
        elif not self.unplug_flag.is_set(): # command packets are buffered
            if code == 0x4064:
                event_kind = struct.unpack(">BIB", data[:6])[2]
                if event_kind in [EVENT_METHOD_ENTRY, EVENT_METHOD_EXIT_WITH_RETURN_VALUE]:
                    self.cmd_pkt_queue.put((ident, code, data))
                elif event_kind == EVENT_BREAKPOINT:
                    Thread(target=self.breakpoint_handler, args=[data]).start()
                elif event_kind == EVENT_CLASS_PREPARE:
                    Thread(target=self.class_prepare_handler, args=[data]).start() 
開發者ID:yzygitzh,項目名稱:ReDroid,代碼行數:21,代碼來源:jdwp.py

示例6: start

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def start(self, join=False):
        """
        when calling with join=True, must call it in main thread, or else, the Keyboard Interrupt won't be caputured.
        :param join: default False, if hold on until the worker is stopped by Ctrl+C or other reasons.
        :return:
        """
        Thread.start(self)

        if join:
            try:
                while self.is_alive():
                    self.join(timeout=60)
                self.logger.info("worker {0} exit unexpected, try to shutdown it".format(self.option.consumer_name))
                self.shutdown()
            except KeyboardInterrupt:
                self.logger.info("*** try to exit **** ")
                self.shutdown() 
開發者ID:aliyun,項目名稱:aliyun-log-python-sdk,代碼行數:19,代碼來源:worker.py

示例7: run

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def run(self):
        self.log(' TaskThread : running ...', prefixname = True)
        while True:
            # If there's not pending task, wait to avoid busy-looping.
            if len(self.tasks) == 0:
                self.wati_for_task.wait()

            # If stop() is called, remaining tasks won't be exectued !
            if self.wati_for_stop.isSet():
                break

            # Remove a pending task from the queue.
            self.__qlock.acquire()
            task = self.tasks.pop(0)
            self.__qlock.release()

            if task:
                self.debug_log(' TaskThread : start executing ... task (%d)'%(task.taskid), prefixname = True)
                task.run()
        self.log(' TaskThread : ending.', prefixname = True) 
開發者ID:PyOCL,項目名稱:OpenCLGA,代碼行數:22,代碼來源:generaltaskthread.py

示例8: started

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def started(self):
        """
        ``True``, if this monitor was started, ``False`` otherwise. Readonly.

        .. seealso:: :meth:`start()`
        .. versionadded:: 0.16
        """
        return self._started 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:10,代碼來源:monitor.py

示例9: filter_by

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def filter_by(self, subsystem, device_type=None):
        """
        Filter incoming events.

        ``subsystem`` is a byte or unicode string with the name of a
        subsystem (e.g. ``'input'``).  Only events originating from the
        given subsystem pass the filter and are handed to the caller.

        If given, ``device_type`` is a byte or unicode string specifying the
        device type.  Only devices with the given device type are propagated
        to the caller.  If ``device_type`` is not given, no additional
        filter for a specific device type is installed.

        These filters are executed inside the kernel, and client processes
        will usually not be woken up for device, that do not match these
        filters.

        .. versionchanged:: 0.15
           This method can also be after :meth:`start()` now.
        """
        subsystem = ensure_byte_string(subsystem)
        if device_type is not None:
            device_type = ensure_byte_string(device_type)
        self._libudev.udev_monitor_filter_add_match_subsystem_devtype(
            self, subsystem, device_type)
        self._libudev.udev_monitor_filter_update(self) 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:28,代碼來源:monitor.py

示例10: receive_device

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def receive_device(self):
        """
        Receive a single device from the monitor.

        .. warning::

           You *must* call :meth:`start()` before calling this method.

        The caller must make sure, that there are events available in the
        event queue.  The call blocks, until a device is available.

        If a device was available, return ``(action, device)``.  ``device``
        is the :class:`Device` object describing the device.  ``action`` is
        a string describing the action.  Usual actions are:

        ``'add'``
          A device has been added (e.g. a USB device was plugged in)
        ``'remove'``
          A device has been removed (e.g. a USB device was unplugged)
        ``'change'``
          Something about the device changed (e.g. a device property)
        ``'online'``
          The device is online now
        ``'offline'``
          The device is offline now

        Raise :exc:`~exceptions.EnvironmentError`, if no device could be
        read.

        .. deprecated:: 0.16
           Will be removed in 1.0. Use :meth:`Monitor.poll()` instead.
        """
        import warnings
        warnings.warn('Will be removed in 1.0. Use Monitor.poll() instead.',
                      DeprecationWarning)
        device = self.poll()
        return device.action, device 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:39,代碼來源:monitor.py

示例11: __iter__

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def __iter__(self):
        """
        Wait for incoming events and receive them upon arrival.

        This methods implicitly calls :meth:`start()`, and starts polling the
        :meth:`fileno` of this monitor.  If a event comes in, it receives the
        corresponding device and yields it to the caller.

        The returned iterator is endless, and continues receiving devices
        without ever stopping.

        Yields ``(action, device)`` (see :meth:`receive_device` for a
        description).

        .. deprecated:: 0.16
           Will be removed in 1.0. Use an explicit loop over :meth:`poll()`
           instead, or monitor asynchronously with :class:`MonitorObserver`.
        """
        import warnings
        warnings.warn('Will be removed in 1.0. Use an explicit loop over '
                      '"poll()" instead, or monitor asynchronously with '
                      '"MonitorObserver".', DeprecationWarning)
        self.start()
        while True:
            device = self.poll()
            if device is not None:
                yield device.action, device 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:29,代碼來源:monitor.py

示例12: start

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def start(self):
        if self.__useThreading:
            Thread.start(self)
        else:
            self.__preRun() 
開發者ID:sprinkler,項目名稱:rainmachine-developer-resources,代碼行數:7,代碼來源:rmParserThread.py

示例13: createInstance

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def createInstance():
        if RMThreadWatcher.instance is None:
            RMThreadWatcher.instance = RMThreadWatcher()
            RMThreadWatcher.instance.start()
        return RMThreadWatcher.instance.isAlive()

    #----------------------------------------------------------------------------------------
    #
    #
    # 
開發者ID:sprinkler,項目名稱:rainmachine-developer-resources,代碼行數:12,代碼來源:rmThreadWatcher.py

示例14: start

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def start(self):
        if not self.__running:
            self.__running = True
            Thread.start(self) 
開發者ID:sprinkler,項目名稱:rainmachine-developer-resources,代碼行數:6,代碼來源:rmThreadWatcher.py

示例15: createInstance

# 需要導入模塊: from threading import Thread [as 別名]
# 或者: from threading.Thread import start [as 別名]
def createInstance():
        if RMCommandThread.instance is None:
            RMCommandThread.instance = RMCommandThread()
            RMCommandThread.instance.start()
        return RMCommandThread.instance.isAlive()

    #----------------------------------------------------------------------------------------
    #
    #
    # 
開發者ID:sprinkler,項目名稱:rainmachine-developer-resources,代碼行數:12,代碼來源:rmCommandThread.py


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