本文整理汇总了Python中threading.Thread.deamon方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.deamon方法的具体用法?Python Thread.deamon怎么用?Python Thread.deamon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threading.Thread
的用法示例。
在下文中一共展示了Thread.deamon方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rpc_server
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def rpc_server(handler, address, authkey):
sock = Listener(address, authkey = authkey)
while True:
client = sock.accept()
t = Thread(target=handler.handle_connection, args=(client,))
t.deamon = True
t.start()
示例2: test_make_fetcher
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def test_make_fetcher():
symmetric362 = SPHERE_FILES['symmetric362']
with TemporaryDirectory() as tmpdir:
stored_md5 = fetcher._get_file_md5(symmetric362)
# create local HTTP Server
testfile_url = op.split(symmetric362)[0] + os.sep
test_server_url = "http://127.0.0.1:8000/"
print(testfile_url)
print(symmetric362)
current_dir = os.getcwd()
# change pwd to directory containing testfile.
os.chdir(testfile_url)
server = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)
server_thread = Thread(target=server.serve_forever)
server_thread.deamon = True
server_thread.start()
# test make_fetcher
sphere_fetcher = fetcher._make_fetcher("sphere_fetcher",
tmpdir, test_server_url,
[op.split(symmetric362)[-1]],
["sphere_name"],
md5_list=[stored_md5])
sphere_fetcher()
assert op.isfile(op.join(tmpdir, "sphere_name"))
npt.assert_equal(fetcher._get_file_md5(op.join(tmpdir, "sphere_name")),
stored_md5)
# stop local HTTP Server
server.shutdown()
# change to original working directory
os.chdir(current_dir)
示例3: on_query_completions
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def on_query_completions(view, prefix, locations):
logging.debug("on_query_completions view id is %s " % view.buffer_id())
if not Tools.is_valid_view(view):
logging.debug(" view id %s is invalid" % view.buffer_id())
return Tools.SHOW_DEFAULT_COMPLETIONS
if not completer:
logging.debug(" completer is invalid")
return Tools.SHOW_DEFAULT_COMPLETIONS
if completer.async_completions_ready:
completer.async_completions_ready = False
#logging.debug(" completions result is %s", completer.completions)
return (completer.completions)
# Verify that character under the cursor is one allowed trigger
pos_status = Tools.get_position_status(locations[0], view, settings)
if pos_status == PosStatus.WRONG_TRIGGER:
return Tools.HIDE_DEFAULT_COMPLETIONS
if pos_status == PosStatus.COMPLETION_NOT_NEEDED:
logging.debug(" show default completions")
return Tools.SHOW_DEFAULT_COMPLETIONS
logging.debug(" starting async auto_complete at pos: %s" %
locations[0])
completion_thread = Thread(
target=completer.complete,
args=[view, locations[0]])
completion_thread.deamon = True
completion_thread.start()
logging.debug(" show default completions last")
return Tools.HIDE_DEFAULT_COMPLETIONS
示例4: dsffsf
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def dsffsf():
global process
if not process:
process = Thread(target = background_thread)
process.deamon = True
process.start()
return "OK", 200
示例5: test_get_clients
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def test_get_clients():
from multiplayer.server import main as server_main
from threading import Thread
t = Thread(target = server_main)
t.deamon = True
t.start()
c = Client(UDPEndpoint(('localhost', 6028)))
c2 = Client(UDPEndpoint(('localhost', 6028)))
return c, c2
示例6: broadcast_command
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def broadcast_command(self, command):
def repeat_pub():
for i in xrange(10):
self.publisher.send(pickle.dumps(command))
time.sleep(1)
t = Thread(target=repeat_pub)
t.deamon = True
t.start()
return t
示例7: process
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def process(self, state):
"""Do whatever you need with the state object state"""
self.last_state = self.current_state
self.current_state = state
world = World(state)
self.policy = Policy(world)
thread = Thread(target=self.policy.policyIteration)
thread.deamon = True
thread.start()
self.thread = thread
示例8: parallelSort
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def parallelSort(l,num_threads):
threads = []
chunked_list = chunkList(l,num_threads)
for chunk in chunked_list:
t = Thread(target=sortList, args=(chunk,))
t.deamon = True
t.start()
threads.append(t)
for t in threads:
t.join()
mergeSortedLists(chunked_list,write_list=l)
示例9: streamResponse
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def streamResponse():
texFile = ""
(fRoot, fExt) = os.path.splitext(f)
if fExt == ".zip":
yield println("Extracting contents of archive...")
os.system("unzip %s -d %s" % (fPath, fDir))
texFile = find_tex(fDir)
elif fExt == ".tex":
texFile = fPath
else:
yield println("File format not recognized: %s" % fExt)
if texFile == "":
yield println("No input file found.")
else:
epubFile = "%s.epub" % fRoot
epubPath = os.path.join(dir_uuid(app.config["DOWNLOAD_FOLDER"], fileid), epubFile)
yield println("Received file %s, converting to %s" % (os.path.basename(texFile), epubFile))
# Launch conversion script
proc = subprocess.Popen(
["python", "-u", "tex2ebook.py", "-o", epubPath, texFile],
stdout=subprocess.PIPE,
stderr=open(os.devnull, "w"),
)
# Start separate thread to read stdout
q = Queue()
t = Thread(target=enqueue_output, args=(proc.stdout, q))
t.deamon = True
t.start()
start = time.time()
running = True
# Read stdout from other thread every second, stop if timeout
while running and time.time() - start < app.config["TIMEOUT"]:
running = proc.poll() is None
try:
line = q.get(timeout=1)
except Empty:
line = ""
else:
yield println(line.rstrip())
if running:
yield println("Timed out.")
# Kill subprocess if timeout occurred
proc.kill()
else:
yield println()
yield println("Done.")
# Redirect to result file
yield '<script type="text/javascript"> $(document).ready(function() { window.location.href = "%s"; }); </script>' % epubPath
yield 'If the download does not start automatically, please click <a href="%s">here</a>.' % epubPath
示例10: run
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def run(self, daemon=True):
"""Executes the command. A thread will be started to collect
the outputs (stderr and stdout) from that command.
The outputs will be written to the queue.
:return: self
"""
self.process = Popen(self.command, bufsize=1,
stdin=PIPE, stdout=PIPE, stderr=STDOUT)
thread = Thread(target=self._queue_output,
args=(self.process.stdout, self.queue))
thread.deamon = daemon
thread.start()
return self
示例11: on_query_completions
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def on_query_completions(view, prefix, locations):
"""Function that is called when user queries completions in the code
Args:
view (sublime.View): current view
prefix (TYPE): Description
locations (list[int]): positions of the cursor (first if many).
Returns:
sublime.Completions: completions with a flag
"""
log.debug(" on_query_completions view id %s", view.buffer_id())
if not Tools.is_valid_view(view):
return Tools.SHOW_DEFAULT_COMPLETIONS
if not completer:
return Tools.SHOW_DEFAULT_COMPLETIONS
if completer.async_completions_ready:
completer.async_completions_ready = False
return (completer.completions, sublime.INHIBIT_WORD_COMPLETIONS |
sublime.INHIBIT_EXPLICIT_COMPLETIONS)
# Verify that character under the cursor is one allowed trigger
pos_status = Tools.get_position_status(locations[0], view, settings)
if pos_status == PosStatus.WRONG_TRIGGER:
# we are at a wrong trigger, remove all completions from the list
return Tools.HIDE_DEFAULT_COMPLETIONS
if pos_status == PosStatus.COMPLETION_NOT_NEEDED:
# show default completions for now if allowed
if settings.hide_default_completions:
log.debug(" hiding default completions")
return Tools.HIDE_DEFAULT_COMPLETIONS
return Tools.SHOW_DEFAULT_COMPLETIONS
# create a daemon thread to update the completions
log.debug(" starting async auto_complete at pos: %s", locations[0])
completion_thread = Thread(
target=completer.complete,
args=[view, locations[0], settings.errors_on_save])
completion_thread.deamon = True
completion_thread.start()
# show default completions for now if allowed
if settings.hide_default_completions:
log.debug(" hiding default completions")
return Tools.HIDE_DEFAULT_COMPLETIONS
return Tools.SHOW_DEFAULT_COMPLETIONS
示例12: __init__
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def __init__(self,**kwargs):
self.workers=[]
self.echonest=None
self.controller=kwargs.get("controller",None)
self.echonest=echonest(kwargs.get("echo_nest_api_key",None))
workers=kwargs.get("workers",1)
Queue.Queue.__init__(self,100)
for i in range(workers):
t=Thread(target=self.worker)
t.deamon=True
t.start()
self.workers.append(t)
示例13: run
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def run(self, daemon=True):
"""
Executes the command. A thread will be started to collect
the outputs (stderr and stdout) from that command.
The outputs will be written to the queue.
"""
# Start the external process
if self.status == "ready":
self.process = Popen(self.command, bufsize=1, shell=True, env=self.environment,
stdin=PIPE, stdout=PIPE, stderr=STDOUT)
# Prepare and start a thread to continiously read the output from the process
thread = Thread(target=self._queue_output,
args=(self.process.stdout, self.queue))
thread.deamon = daemon
thread.start()
# Return self as the iterator object
return self
示例14: test_fetch_data
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def test_fetch_data():
symmetric362 = SPHERE_FILES['symmetric362']
with TemporaryDirectory() as tmpdir:
md5 = fetcher._get_file_md5(symmetric362)
bad_md5 = '8' * len(md5)
newfile = op.join(tmpdir, "testfile.txt")
# Test that the fetcher can get a file
testfile_url = symmetric362
print(testfile_url)
testfile_dir, testfile_name = op.split(testfile_url)
# create local HTTP Server
test_server_url = "http://127.0.0.1:8001/" + testfile_name
current_dir = os.getcwd()
# change pwd to directory containing testfile.
os.chdir(testfile_dir + os.sep)
# use different port as shutdown() takes time to release socket.
server = HTTPServer(('localhost', 8001), SimpleHTTPRequestHandler)
server_thread = Thread(target=server.serve_forever)
server_thread.deamon = True
server_thread.start()
files = {"testfile.txt": (test_server_url, md5)}
fetcher.fetch_data(files, tmpdir)
npt.assert_(op.exists(newfile))
# Test that the file is replaced when the md5 doesn't match
with open(newfile, 'a') as f:
f.write("some junk")
fetcher.fetch_data(files, tmpdir)
npt.assert_(op.exists(newfile))
npt.assert_equal(fetcher._get_file_md5(newfile), md5)
# Test that an error is raised when the md5 checksum of the download
# file does not match the expected value
files = {"testfile.txt": (test_server_url, bad_md5)}
npt.assert_raises(fetcher.FetcherError,
fetcher.fetch_data, files, tmpdir)
# stop local HTTP Server
server.shutdown()
# change to original working directory
os.chdir(current_dir)
示例15: main
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import deamon [as 别名]
def main():
host = "10.6.161.65"
port = 8880
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((host, port))
connection_addr = Upd_client_address_container()
d = Thread(target=wait_response, args=(s, connection_addr,))
d.deamon = True
d.start()
print("Server started")
message = 'Connection with server established'
while message != 'q':
if connection_addr.addr:
s.sendto(message.encode('utf-8'), connection_addr.addr)
message = raw_input("->")
s.close()