本文整理汇总了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()
示例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))
示例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)
示例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()
示例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
示例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)
示例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
示例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()