当前位置: 首页>>代码示例>>Python>>正文


Python Thread.deamon方法代码示例

本文整理汇总了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()
开发者ID:JperF,项目名称:OODP_python,代码行数:9,代码来源:rpcserver.py

示例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)
开发者ID:MPDean,项目名称:dipy,代码行数:36,代码来源:test_fetcher.py

示例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
开发者ID:HuiMi24,项目名称:TtcnComplete,代码行数:36,代码来源:ttcn3.py

示例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
开发者ID:benoitmangili,项目名称:eveningmeeting_fun,代码行数:10,代码来源:gpio_part_5.py

示例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
开发者ID:niccokunzmann,项目名称:multiplayer,代码行数:11,代码来源:client.py

示例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
开发者ID:guibog,项目名称:dpark,代码行数:12,代码来源:scheduler.py

示例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
开发者ID:MVilstrup,项目名称:Vindinium,代码行数:12,代码来源:ai.py

示例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)
开发者ID:ericchiang,项目名称:weatherTweets,代码行数:15,代码来源:utils.py

示例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
开发者ID:rzoller,项目名称:tex2ebook,代码行数:53,代码来源:webapp.py

示例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
开发者ID:interru,项目名称:ffmpegwrapper,代码行数:16,代码来源:ffmpeg.py

示例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
开发者ID:shaurya0,项目名称:EasyClangComplete,代码行数:51,代码来源:EasyClangComplete.py

示例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)
开发者ID:openStove,项目名称:streamripper_tray,代码行数:18,代码来源:streamripper_tagger.py

示例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
开发者ID:Draco-,项目名称:Python_Classes,代码行数:19,代码来源:externalProcess.py

示例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)
开发者ID:MPDean,项目名称:dipy,代码行数:45,代码来源:test_fetcher.py

示例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()
开发者ID:Sergei-Rudenkov,项目名称:peer-to-peer-UDP,代码行数:22,代码来源:UDPserver.py


注:本文中的threading.Thread.deamon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。