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


Python Thread.setName方法代码示例

本文整理汇总了Python中threading.Thread.setName方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.setName方法的具体用法?Python Thread.setName怎么用?Python Thread.setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在threading.Thread的用法示例。


在下文中一共展示了Thread.setName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_reactor

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
def get_reactor():
    """
    Start the Twisted reactor in a separate thread, if not already done.
    Returns the reactor.
    The thread will automatically be destroyed when all the tests are done.
    """
    global _twisted_thread, _reactor

    if _twisted_thread:
        return _reactor

    def reactor_run():
        _reactor.__init__()
        _reactor._startedBefore = False
        _reactor._started = False
        _reactor.run(installSignalHandlers=False)

    from twisted.internet import reactor as twisted_reactor
    _reactor = twisted_reactor

    _twisted_thread = Thread(target=reactor_run)
    _twisted_thread.setName('threaded_reactor')
    _twisted_thread.setDaemon(True)
    _twisted_thread.start()

    # Wait a bit for the reactor to start.
    time.sleep(0.01)
    return _reactor
开发者ID:chevah,项目名称:compat,代码行数:30,代码来源:threaded_reactor.py

示例2: init

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
 def init(self, callback = None, timeout = 10):
     if callback is None:
         return self._init()
     t = Thread(target=self._init, args=[callback, timeout])
     t.setName('dd-downloader-init-' + t.getName())
     t.setDaemon(True)
     t.start()
开发者ID:2jangelman,项目名称:P2P-Streams-XBMC--Modules-,代码行数:9,代码来源:Downloader.py

示例3: get_dir

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
def get_dir(db=None):
    if db is None:
        db = MySQLdb.connect(**config.mysql)
    files = os.listdir(config.torrents_dir)
    hashs = [h[:-8] for h in files if h.endswith(".torrent")]
    cur = db.cursor()
    cur.execute("SELECT hash FROM torrents WHERE created_at IS NULL AND (%s)"  % " OR ".join("hash=%s" for hash in hashs), tuple(hashs))
    ret = [r[0] for r in cur]
    new_hash = set(hashs).difference(ret)
    count = len(new_hash)
    done=0
    new_hashq = queue.Queue()
    [new_hashq.put(h) for h in new_hash]
    pbar = progressbar.ProgressBar(widgets=widget("inserting torrents in db"), maxval=count).start()
    cur.close()
    try:
        threads = []
        for i in range(0, 20):
            t = Thread(target=insert, args=(new_hashq, pbar))
            t.setName("insert-%02d" % i)
            t.daemon = True
            t.start()
            threads.append(t)
        join(threads)
    finally:
        print("")
        db.commit()

    cur.close()
    return ret + list(new_hash)
开发者ID:henrytrager,项目名称:openbay-crawler,代码行数:32,代码来源:feed.py

示例4: start_thread

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
def start_thread(target, as_daemon, name = None):
    thread = Thread(target = target)
    if name:
        thread.setName(name)
    thread.setDaemon(as_daemon)
    thread.start()
    return thread
开发者ID:mjcowdrill,项目名称:python,代码行数:9,代码来源:mc_actor_pattern.py

示例5: rerequest

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
    def rerequest(self, s, callback):
        # ProxyService_
        #
        proxy_mode = self.config.get('proxy_mode',0)
        if DEBUG:
            if proxy_mode == PROXY_MODE_PRIVATE:
                if True:
                    print "_rerequest exited."# + str(proxy_mode)
                return
            else:
                if True:
                    print "_rerequest did not exit"# + str(proxy_mode) 
        #
        # _ProxyService

        if not self.lock.isfinished():  # still waiting for prior cycle to complete??
            def retry(self = self, s = s, callback = callback):
                self.rerequest(s, callback)
            self.sched(retry, 5)         # retry in 5 seconds
            return
        self.lock.reset()
        rq = Thread(target = self._rerequest, args = [s, callback])
        rq.setName( "TrackerRerequestA"+rq.getName() )
        # Arno: make this a daemon thread so the client closes sooner.
        rq.setDaemon(True)
        rq.start()
开发者ID:Anaconda84,项目名称:Anaconda,代码行数:28,代码来源:Rerequester.py

示例6: ThreadedHTTPServer

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
    def __init__(self, address, port, requestHandler):
        self._requestHandler = requestHandler
        self._port = port
        self._running = True

        TCPServer.__init__(self, (address, port), HTTPRequestHandler)

    @property
    def requestHandler(self):
        return self._requestHandler

    def server_bind(self):
        self.allow_reuse_address = True
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.socket.bind(self.server_address)

        logger.debug('Starting TCP server at %s' % str(self.server_address))


    def start(self):
        self._thread = Thread(target=self.serve_forever)
        self._thread.setName('ServerThread')
        self._thread.start()

    def stop(self):
        self.shutdown()
        self._thread.join()
开发者ID:spiricn,项目名称:ssc,代码行数:30,代码来源:ThreadedHTTPServer.py

示例7: onOpenDest

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
 def onOpenDest(self, event = None, openFile=False):
     # open Destination
     item = self.standardDetails.getData()
     state = item.get('ds')
     
     if state:
         dest = state.get_download().get_dest_dir()
         if openFile:
             destfiles = state.get_download().get_dest_files()
             if len(destfiles) == 1:
                 dest = destfiles[0][1]
         if sys.platform == 'darwin':
             dest = 'file://%s' % dest
         
         print >> sys.stderr, dest
         complete = True
         # check if destination exists
         assert dest is not None and os.access(dest, os.R_OK), 'Could not retrieve destination'
         try:
             t = Thread(target = open_new, args=(str(dest),))
             t.setName( "FilesOpenNew"+t.getName() )
             t.setDaemon(True)
             t.start()
         except:
             print_exc()
             pass
             
     elif DEBUG:
         print >>sys.stderr,'GUIUtil: onOpenFileDest failed: no torrent selected'
开发者ID:nomadsummer,项目名称:cs198mojo,代码行数:31,代码来源:GuiUtility.py

示例8: __init__

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
    def __init__(self, options, q_out):
	FuzzQueue.__init__(self, q_out, options.get("max_concurrent") * 5)

	self.options = options

	self.processed = 0

	self.exit_job = False
	self.mutex_multi = Lock()
	self.mutex_stats = Lock()

	self.queue_out = q_out

	# Connection pool
	self.m = None
	self.freelist = Queue()
	self.create_pool(options.get("max_concurrent"))

	th2 = Thread(target=self.__read_multi_stack)
	th2.setName('__read_multi_stack')
	th2.start()

	self.pause = Event()
	self.pause.set()

	self._proxies = None
	if options.get("proxy_list"):
	    self._proxies = self.__get_next_proxy(options.get("proxy_list"))
开发者ID:601040605,项目名称:wfuzz,代码行数:30,代码来源:myhttp.py

示例9: download

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
 def download(self):
     if DEBUG:
         print 'http-sdownload: download()'
     if self.is_frozen_by_helper():
         if DEBUG:
             print 'http-sdownload: blocked, rescheduling'
         self.resched(1)
         return
     self.cancelled = False
     if self.downloader.picker.am_I_complete():
         self.downloader.downloads.remove(self)
         return
     self.index = self.downloader.picker.next(haveall, self._want, self)
     if self.index is None and self.frozen_by_helper:
         self.resched(0.01)
         return
     if self.index is None and not self.endflag and not self.downloader.peerdownloader.has_downloaders():
         self.endflag = True
         self.index = self.downloader.picker.next(haveall, self._want, self)
     if self.index is None:
         self.endflag = True
         self.resched()
     else:
         self.url = self.seedurl + '&piece=' + str(self.index)
         self._get_requests()
         if self.request_size < self.downloader.storage._piecelen(self.index):
             self.url += '&ranges=' + self._request_ranges()
         rq = Thread(target=self._request)
         rq.setName('HoffmanHTTPDownloader' + rq.getName())
         rq.setDaemon(True)
         rq.start()
         self.active = True
开发者ID:salekseev,项目名称:freestream,代码行数:34,代码来源:HoffmanHTTPDownloader.py

示例10: deadlocks

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
 def deadlocks(f, t):
     th = Thread(target = f)
     th.setName("Thread")
     th.setDaemon(1)
     th.start()
     th.join(t)
     return th.isAlive()
开发者ID:HatsuneMiku,项目名称:clojure-py,代码行数:9,代码来源:shared_lock.py

示例11: start

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
	def start(self):
		if not self.pid:
			classPath = os.path.join(sourcePath, self.__deployDir, 'lib/*')
			# 如下的命令不会返回结果, 需要通过线程执行
			demoThread = Thread(target=executeCmdAndReturn,
			                    args=(['nohup java -jar ' + self.__targetJar + ' -classpath ' + classPath + ' &']),
			                    kwargs={'cwd': os.path.join(sourcePath, self.__deployDir), 'shell': True, 'log': True})
			demoThread.setDaemon(True)
			demoThread.setName('io-all启动线程')
			demoThread.start()
			count = 0
			while not count:
				record('.', terminator='')
				sleep(1)
				if self.__serverPort and self.__serverProtocol == 'dubbo':
					returnCode, out, _ = executeCmdAndReturn(
						['echo status | nc -i 1 127.0.0.1 ' + self.__serverPort + ' | grep -c OK'],
						shell=True)
					if returnCode == 0:
						count = int(out)
				else:
					if self.isStarted():
						count = 1

				if count > 0:
					break
开发者ID:18965050,项目名称:python-RelaseScript,代码行数:28,代码来源:server.py

示例12: start

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
    def start(self):
        # doing some initialisation
        if self.master:
            self.root.hash_to_ignore = HashToIgnore()
            self.root.update_hash = set()
            self.root.update_hash_lock = Lock()
            self.root.bad_info_hash = {}
            self.root.good_info_hash = {}
            self.root.last_update_hash = 0
        self.hash_to_fetch = collections.OrderedDict()
        self.hash_to_fetch_tried = collections.defaultdict(set)
        self.hash_to_fetch_totry = collections.defaultdict(set)

        # calling parent method
        super(Crawler, self).start()

        # starting threads
        for f, name in [(self._client_loop, 'client_loop')]:
            t = Thread(target=f)
            t.setName("%s:%s" % (self.prefix, name))
            t.daemon = True
            t.start()
            self._threads.append(t)
            self.threads.append(t)
        if self.master:
            # addings threads to parent threads list
            self.root.client.start()
            self._threads.extend(self.root.client.threads)
            self.threads.extend(self.root.client.threads)
开发者ID:henrytrager,项目名称:openbay-crawler,代码行数:31,代码来源:crawler.py

示例13: aggregate_senddata

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
 def aggregate_senddata(self, query):
     url = self.aggregate_forward + '?' + query
     if self.aggregate_password is not None:
         url += '&password=' + self.aggregate_password
     rq = Thread(target=self._aggregate_senddata, args=[url])
     rq.setName('AggregateSendData' + rq.getName())
     rq.setDaemon(True)
     rq.start()
开发者ID:salekseev,项目名称:freestream,代码行数:10,代码来源:track.py

示例14: start

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
 def start(self):
     self.stoped = False
     self.id = str(ID())
     t = Thread(target=self._recv_loop)
     t.setName("Client:recv_loop")
     t.daemon = True
     t.start()
     self.threads.append(t)
开发者ID:henrytrager,项目名称:openbay-crawler,代码行数:10,代码来源:torrent.py

示例15: predownload

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import setName [as 别名]
 def predownload(self, callback, timeout = 10):
     if self.lock.locked():
         self.seek = pos
         return
     t = Thread(target=self._predownload, args=[callback, timeout])
     t.setName('dd-downloader-predownload-' + t.getName())
     t.setDaemon(True)
     t.start()
开发者ID:2jangelman,项目名称:P2P-Streams-XBMC--Modules-,代码行数:10,代码来源:Downloader.py


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