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


Python dummy_threading.Thread方法代碼示例

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


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

示例1: _reader

# 需要導入模塊: import dummy_threading [as 別名]
# 或者: from dummy_threading import Thread [as 別名]
def _reader(self, name, stream, outbuf):
        """
        Thread runner for reading lines of from a subprocess into a buffer.

        :param name: The logical name of the stream (used for logging only).
        :param stream: The stream to read from. This will typically a pipe
                       connected to the output stream of a subprocess.
        :param outbuf: The list to append the read lines to.
        """
        while True:
            s = stream.readline()
            if not s:
                break
            s = s.decode('utf-8').rstrip()
            outbuf.append(s)
            logger.debug('%s: %s' % (name, s))
        stream.close() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:index.py

示例2: test_make_msgid_collisions

# 需要導入模塊: import dummy_threading [as 別名]
# 或者: from dummy_threading import Thread [as 別名]
def test_make_msgid_collisions(self):
        # Test make_msgid uniqueness, even with multiple threads
        class MsgidsThread(Thread):
            def run(self):
                # generate msgids for 3 seconds
                self.msgids = []
                append = self.msgids.append
                make_msgid = Utils.make_msgid
                clock = time.time
                tfin = clock() + 3.0
                while clock() < tfin:
                    append(make_msgid())

        threads = [MsgidsThread() for i in range(5)]
        with start_threads(threads):
            pass
        all_ids = sum([t.msgids for t in threads], [])
        self.assertEqual(len(set(all_ids)), len(all_ids)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_email.py

示例3: start

# 需要導入模塊: import dummy_threading [as 別名]
# 或者: from dummy_threading import Thread [as 別名]
def start(self):
        """Starts the worker threads"""
        if self.working:
            return
        self.working = True
        for i in range(self.num_workers):
            w = threading.Thread(
                name="Worker Thread #{i}".format(i=i),
                target=self._worker,
                )
            w.daemon = True
            w.start()
            self.workers.append(w) 
開發者ID:CodeReclaimers,項目名稱:neat-python,代碼行數:15,代碼來源:threaded.py

示例4: process_request

# 需要導入模塊: import dummy_threading [as 別名]
# 或者: from dummy_threading import Thread [as 別名]
def process_request(self, request, client_address):
        """Start a new thread to process the request."""
        t = threading.Thread(target = self.process_request_thread,
                             args = (request, client_address))
        t.daemon = self.daemon_threads
        t.start() 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:8,代碼來源:socketserver.py

示例5: run_command

# 需要導入模塊: import dummy_threading [as 別名]
# 或者: from dummy_threading import Thread [as 別名]
def run_command(self, cmd, **kwargs):
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE, **kwargs)
        t1 = threading.Thread(target=self.reader, args=(p.stdout, 'stdout'))
        t1.start()
        t2 = threading.Thread(target=self.reader, args=(p.stderr, 'stderr'))
        t2.start()
        p.wait()
        t1.join()
        t2.join()
        if self.progress is not None:
            self.progress('done.', 'main')
        elif self.verbose:
            sys.stderr.write('done.\n')
        return p 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:17,代碼來源:util.py

示例6: _prepare_threads

# 需要導入模塊: import dummy_threading [as 別名]
# 或者: from dummy_threading import Thread [as 別名]
def _prepare_threads(self):
        """
        Threads are created only when get_project is called, and terminate
        before it returns. They are there primarily to parallelise I/O (i.e.
        fetching web pages).
        """
        self._threads = []
        for i in range(self.num_workers):
            t = threading.Thread(target=self._fetch)
            t.setDaemon(True)
            t.start()
            self._threads.append(t) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:locators.py

示例7: run_command

# 需要導入模塊: import dummy_threading [as 別名]
# 或者: from dummy_threading import Thread [as 別名]
def run_command(self, cmd, input_data=None):
        """
        Run a command in a child process , passing it any input data specified.

        :param cmd: The command to run.
        :param input_data: If specified, this must be a byte string containing
                           data to be sent to the child process.
        :return: A tuple consisting of the subprocess' exit code, a list of
                 lines read from the subprocess' ``stdout``, and a list of
                 lines read from the subprocess' ``stderr``.
        """
        kwargs = {
            'stdout': subprocess.PIPE,
            'stderr': subprocess.PIPE,
        }
        if input_data is not None:
            kwargs['stdin'] = subprocess.PIPE
        stdout = []
        stderr = []
        p = subprocess.Popen(cmd, **kwargs)
        # We don't use communicate() here because we may need to
        # get clever with interacting with the command
        t1 = Thread(target=self._reader, args=('stdout', p.stdout, stdout))
        t1.start()
        t2 = Thread(target=self._reader, args=('stderr', p.stderr, stderr))
        t2.start()
        if input_data is not None:
            p.stdin.write(input_data)
            p.stdin.close()

        p.wait()
        t1.join()
        t2.join()
        return p.returncode, stdout, stderr 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:36,代碼來源:index.py

示例8: process_request

# 需要導入模塊: import dummy_threading [as 別名]
# 或者: from dummy_threading import Thread [as 別名]
def process_request(self, request, client_address):
        """Start a new thread to process the request."""
        t = threading.Thread(target = self.process_request_thread,
                             args = (request, client_address))
        if self.daemon_threads:
            t.setDaemon (1)
        t.start() 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:9,代碼來源:SocketServer.py


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