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


Python Thread.getName方法代码示例

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


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

示例1: _transfer

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [as 别名]
	def _transfer(self, files, action):
		# Enqueue 
		queue = Queue()
		for file in files:
			os.access(file, os.R_OK)
			queue.put((file, 0)) 

		workers = []
		failed_files = []
		result = dict()
		
		self._failed_files_lock = Lock()
		
		#Starting threads
		for n in range(min(self._pool, len(files))):
			worker = Thread(name="Worker-%s" % n, target=self._worker, 
					args=(action, queue, result, failed_files))
			self._logger.debug("Starting worker '%s'", worker.getName())
			worker.start()
			workers.append(worker)
		
		# Join workers
		for worker in workers:
			worker.join()
			self._logger.debug("Worker '%s' finished", worker.getName())
	
		if failed_files:
			raise TransferError("Cannot process several files. %s" % [", ".join(failed_files)])
		
		self._logger.info("Transfer complete!")

		# Return tuple of all files	def set_access_data(self, access_data):
		self._logger.debug('Transfer result: %s', (result,))
		return tuple(result[file] for file in files)
开发者ID:golovast,项目名称:scalarizr,代码行数:36,代码来源:transfer.py

示例2: run_async

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [as 别名]
def run_async(func, *args, **kwargs):
    from threading import Thread

    worker = Thread(target=func, args=args, kwargs=kwargs)
    __workersByName[worker.getName()] = worker
    worker.start()
    return worker
开发者ID:Stevie-Bs,项目名称:ru,代码行数:9,代码来源:StorageServer.py

示例3: onOpenDest

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [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

示例4: __init__

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [as 别名]
 def __init__(self, host='', port=58858):
     self.port = port
     self.handler = ThreadedHttpRequestHandler
     #load gps icon into handler memory
     self.iconhref = '/gps.png</href>'
     d = abspath(workdir + '/rc/gps.png')
     f = open(d, 'rb')
     self.handler.iconPng = f.read()
     f.close()
     #load plugin.html into handler memory
     d = abspath(workdir + '/rc/plugin.html')
     f = open(d, 'r')
     self.handler.plugin = f.read()
     f.close()
     #load gps.kml template into self memory
     d = abspath(workdir + '/rc/gps.kml')
     f = open(d, 'r')
     self.gps_template = f.read()
     f.close()
     #push gps.kml into handler memory
     self.updateKML() #self.gps
     
     self.server = HTTPServer((host, port), self.handler)
     server_thread = Thread(target=self.server.serve_forever, name='kmld-thread')
     server_thread.setDaemon(True)
     server_thread.start()
     print "Server loop running in thread:", server_thread.getName()
开发者ID:manimaul,项目名称:Matrix-Mariner-GPS,代码行数:29,代码来源:Kml.py

示例5: init

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [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

示例6: rerequest

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [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

示例7: download

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [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

示例8: run_async

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [as 别名]
def run_async(func, *args, **kwargs):
    """
        run_async(func)
            function decorator, intended to make "func" run in a separate
            thread (asynchronously).
            Returns the created Thread object

            E.g.:
            @run_async
            def task1():
                do_something

            @run_async
            def task2():
                do_something_too

            t1 = task1()
            t2 = task2()
            ...
            t1.join()
            t2.join()
    """
    from threading import Thread
    worker = Thread(target = func, args = args, kwargs = kwargs)
    __workersByName[worker.getName()] = worker
    worker.start()
    # TODO: attach post-func decorator to target function and remove thread from __workersByName
    return worker
开发者ID:Berimor66,项目名称:mythbox,代码行数:30,代码来源:util.py

示例9: interval_host

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [as 别名]
def interval_host(host, time, f, *args, **kwargs):
    '''
    Creates an Event attached to the *host* that will execute the *f*
    function every *time* seconds.

    See example in :ref:`sample_inter`

    :param Proxy host: proxy of the host. Can be obtained from inside a
        class with ``self.host``.
    :param int time: seconds for the intervals.
    :param func f: function to be called every *time* seconds.
    :param list args: arguments for *f*.
    :return: :class:`Event` instance of the interval.
    '''
    def wrap(*args, **kwargs):
        thread = currentThread()
        args = list(args)
        stop_event = args[0]
        del args[0]
        args = tuple(args)
        while not stop_event.is_set():
            f(*args, **kwargs)
            stop_event.wait(time)
        host.detach_interval(thread_id)
    t2_stop = Event()
    args = list(args)
    args.insert(0, t2_stop)
    args = tuple(args)
    t = Thread(target=wrap, args=args, kwargs=kwargs)
    t.start()
    thread_id = t.getName()
    host.attach_interval(thread_id, t2_stop)
    return t2_stop
开发者ID:pedrotgn,项目名称:pyactor,代码行数:35,代码来源:intervals.py

示例10: predownload

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [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

示例11: aggregate_senddata

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [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

示例12: log_on_threads

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [as 别名]
def log_on_threads(message, name_prefix, count):
    for i in range(int(count)):
        name = '%s %d' % (name_prefix, i+1)
        thread = Thread(name=name, target=logger.info,
                        args=['%s says <i>%s</i>.' % (name, message)],
                        kwargs={'html': True})
        thread.start()
        threads[thread.getName()] = thread
开发者ID:robotframework,项目名称:robotbackgroundlogger,代码行数:10,代码来源:example.py

示例13: getName

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [as 别名]
 def getName (self, engine=None):
     # Test if the call was to get the name of the thread
     if engine is None:
         return Thread.getName(self)
     
     nametag = engine.find("meta/name")
     if nametag is not None:
         return nametag.text.strip()
     return engine.get('binname')
开发者ID:jskurka,项目名称:PyChess-Learning-Module,代码行数:11,代码来源:engineNest.py

示例14: threads

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [as 别名]
def threads(uuid, n=10):
    for i in range(0, n):
        agent = Agent(uuid)
        name = "Test%d" % i
        t = Thread(name=name, target=main, args=(uuid,))
        t.setDaemon(True)
        t.start()
        print "thread: %s, started" % t.getName()
    return t
开发者ID:splice,项目名称:gofer,代码行数:11,代码来源:server.py

示例15: threads

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import getName [as 别名]
def threads(n=10):
    t = None
    for i in range(0, n):
        name = 'Test%d' % i
        t = Thread(name=name, target=main)
        t.setDaemon(True)
        t.start()
        print 'thread: %s, started' % t.getName()
    return t
开发者ID:roshan,项目名称:gofer,代码行数:11,代码来源:server.py


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