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


Python Thread.run方法代码示例

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


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

示例1: run

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
 def run(self):
     try:
         Thread.run(self)
     except Exception, e:
         self._exc = ThreadError("Uncaught exception in a thread %s\n%s" %
                 (self.getName(), '\n'.join(
                     ' | ' + line for line in format_exc().splitlines())))
开发者ID:findepi,项目名称:pymx,代码行数:9,代码来源:testlib_threads.py

示例2: run

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
    def run(self):
        global exitthreads
        self.threadid = get_ident()
        try:
            if not ExitNotifyThread.profiledir: # normal case
                Thread.run(self)
            else:
                try:
                    import cProfile as profile
                except ImportError:
                    import profile
                prof = profile.Profile()
                try:
                    prof = prof.runctx("Thread.run(self)", globals(), locals())
                except SystemExit:
                    pass
                prof.dump_stats(os.path.join(ExitNotifyThread.profiledir,
                                "%s_%s.prof" % (self.threadid, self.getName())))
        except:
            self.setExitCause('EXCEPTION')
            if sys:
                self.setExitException(sys.exc_info()[1])
                tb = traceback.format_exc()
                self.setExitStackTrace(tb)
        else:
            self.setExitCause('NORMAL')
        if not hasattr(self, 'exitmessage'):
            self.setExitMessage(None)

        if exitthreads:
            exitthreads.put(self, True)
开发者ID:AndreaCrotti,项目名称:offlineimap,代码行数:33,代码来源:threadutil.py

示例3: run

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
    def run(self):
        """Allow profiling of a run and store exceptions."""

        global exitedThreads
        try:
            if not ExitNotifyThread.profiledir: # normal case
                Thread.run(self)
            else:
                try:
                    import cProfile as profile
                except ImportError:
                    import profile
                prof = profile.Profile()
                try:
                    prof = prof.runctx("Thread.run(self)", globals(), locals())
                except SystemExit:
                    pass
                prof.dump_stats(os.path.join(ExitNotifyThread.profiledir,
                                "%s_%s.prof"% (self.ident, self.getName())))
        except Exception as e:
            # Thread exited with Exception, store it
            tb = traceback.format_exc()
            self.set_exit_exception(e, tb)

        exitedThreads.put(self, True)
开发者ID:khatchad,项目名称:offlineimap,代码行数:27,代码来源:threadutil.py

示例4: main

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
def main():

    usage = """usage %prog -H <target host> -p <target ports>

examples:
    %prog -H 127.0.0.1 -p 22
    %prog -H www.google.com -p 80,443
    %prog -H 127.0.0.1 -p 22,8000-8010"""

    parser = optparse.OptionParser( usage )

    parser.add_option( '-H', dest = 'tgtHost',  type = 'string', help = 'specify the target host' )
    parser.add_option( '-p', dest = 'tgtPorts', type = 'string', help = 'specify the target ports - comma delmited, no spaces' )

    ( options, args ) = parser.parse_args()

    if options.tgtHost == None or options.tgtPorts == None:
        print
        parser.print_help()
        print
        exit(0)

    tgtHost = options.tgtHost
    tgtPorts = options.tgtPorts.split(',')

    print "Port scan report for: %s" % tgtHost
    for tgtPort in tgtPorts:
            if tgtPort.find('-') > 0:
                (start, end) = tgtPort.split('-')
                for tgtPort in range(int(start),int(end)+1):
                    t = Thread( target=nmapScan, args = ( tgtHost, str(tgtPort) ) )
                    t.run()
            else:
                t = Thread( target=nmapScan, args = ( tgtHost, tgtPort ) )
                t.run()
开发者ID:slabgrha,项目名称:secops,代码行数:37,代码来源:scanNmap.py

示例5: run

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
    def run(self):
        try:
            plugin = self.__plugin

            arguments = plugin.getArguments()
            dialog = ProcessJobDialog(plugin.getName(), plugin.getParentWindow())

            dialog.cancelConfirmed.connect(self.cancel)

            run_function = partial(self.__runWorkflowJob, plugin, arguments)

            workflow_job_thread = Thread(name="ert_gui_workflow_job_thread")
            workflow_job_thread.setDaemon(True)
            workflow_job_thread.run = run_function
            workflow_job_thread.start()


            poll_function = partial(self.__pollRunner, plugin, dialog)

            poll_thread = Thread(name="ert_gui_workflow_job_poll_thread")
            poll_thread.setDaemon(True)
            poll_thread.run = poll_function
            poll_thread.start()

            dialog.show()
        except CancelPluginException:
            print("Plugin cancelled before execution!")
开发者ID:berland,项目名称:ert,代码行数:29,代码来源:plugin_runner.py

示例6: update_information

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
    def update_information(self, client_basis, server_basis, content):
        local_basis = client_basis
        self.local_basis = client_basis
        self.server_basis = server_basis

        if client_basis == Utils.UNKNOWN_HASH:
            local_basis = self.UNKNOWN_BASIS_STRING

        self.message_label.SetLabel(self.mismatch_message % {
                                            'client_hash': local_basis,
                                            'server_hash': server_basis
                                   })

        updateRobots = Thread(target=self.updateRobotHash)
        updateRobots.daemon = True
        updateRobots.run()
        if len(content) == 0:
            self.panel_2.give_message(Messages.BASIS_MISMATCH_NOTHING_TO_SYNC)
        for element in reversed(content):
            if u'newpathname' in element:
                self.panel_2.updatePathnameStatus(element[u'pathname'],
                                                  element[u'status'],
                                                  element[u'size'],
                                                  element[u'newpathname'])
            else:
                self.panel_2.updatePathnameStatus(element[u'pathname'],
                                                  element[u'status'],
                                                  element[u'size'])
开发者ID:alepharchives,项目名称:FileRock-Client,代码行数:30,代码来源:SyncDialog.py

示例7: _run_commands_capture_output

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
 def _run_commands_capture_output(self, commands):
     """Runs the specified commands, kill them if the timeout is exceeded, 
     and returns anything the program(s) output on stdout or stderr.
     commands must be a list of commands to run where each command to run
     is a list with the command to run in the 0th element followed by the 
     args in the following positions. Eg:
     [
         ["ls"],
         ["mv", "foo", "bar"]
     ]
     Can raise ExecutionTimedOutError.
     Implementation: This function spawns a second thread to do the execution
     of the commands and read their output into a class variable. Since that 
     thread doesn't block on anything and reads both stdout and stderr in one
     stream, there shouldn't be any possible deadlocks.
     The first thread does the timing and kills the child process if the 
     timeout specified in the settings is exceeded. Then it returns the data 
     captured by the second thread.
     """
     assert type(commands) == list
     assert len(commands) > 0
     assert type(commands[0]) == list
     assert len(commands[0]) > 0
     self.commands_output = ""
     # commands needs to be in [] because the call dereferences one set of brackets
     run_commands_thread = Thread(target=self.__actual_run_commands_capture_output, args=[commands])
     # TODO start timer
     run_commands_thread.run()
     # TODO kill process when timer expires
     return self.commands_output
开发者ID:BackupTheBerlios,项目名称:cocoman-svn,代码行数:32,代码来源:languagesupport.py

示例8: run

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
    def run(self):
        Thread.run(self)

        while True:

            if(not self.irqToQueue == None):
                self.currentDevice.pushToQueue(self.irqToQueue)
                self.irqToQueue= None
开发者ID:ilaborde,项目名称:Sistemas-Operativos-Unqui,代码行数:10,代码来源:deviceManager.py

示例9: Claybot

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
class Claybot():
    def __init__(self):
        self.hm = hm = pyHook.HookManager()
        self.running = False
        self.thread = None
        self.hm.HookMouse()
        
    def begin(self):
        self.hm.MouseLeftDown = self.on_left_click
        self.running = True
        while self.running:
            pythoncom.PumpWaitingMessages()
        
    def on_left_click(self, e):
        self.hm.MouseLeftDown = None
        self.hm.MouseRightDown = self.on_right_click
        self.spawn_thread()
        return True
        
    def spawn_thread(self):
        self.thread = Thread(None, self.threadloop)
        self.thread.run()
            
    def threadloop(self):
        last = time()
        interval = 3.9
        plusminus = 0.1
        int_min = interval - plusminus
        int_max = interval + plusminus
        int_sz = int_max - int_min
        
        def next_wait():
            return last + int_min + random() * int_sz
            
        t_next = next_wait()
        t = time()
        import pdb
        pdb.set_trace()
        
        while self.running:
            t = time()
            if t > t_next:
                print("t", t, "last", last, "t_next", t_next)
                x, y = GetCursorPos()
                click(x, y)
                last = t
                t_next = next_wait()
                
        
    def on_right_click(self, e):
        self.unhook()
        self.running = False
        if self.thread:
            self.thread.join()
        return True
        
    def unhook(self):
        self.hm.MouseRightDown = None
开发者ID:nitetrain8,项目名称:pysrc2,代码行数:60,代码来源:claybot.py

示例10: gameover

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
        def gameover():  # 游戏结束状态
            self.timer.stop()

            if hasattr(self.gameover_callback, '__call__') is True:
                gameover_thread = Thread(target=self.gameover_callback)
                gameover_thread.setDaemon(True)
                gameover_thread.run()

            self.state = "stopped"
开发者ID:aheadlead,项目名称:PyTetris,代码行数:11,代码来源:model.py

示例11: run

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
    def run(self):
        """
python.org: Method representing the thread's activity.

:since: v0.2.00
        """

        with ExceptionLogTrap("pas_upnp"):
            Thread.run(self)
开发者ID:dNG-git,项目名称:pas_upnp,代码行数:11,代码来源:abstract_event.py

示例12: run

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
 def run(self):
     log.info('# %s # is about to acquire the globallock' % getcurrent())
     globallock.acquire()
     log.info('# %s # acquired the globallock' % getcurrent())
     try:
         Thread.run(self)
     finally:
         self.tasklet.remove()
         schedule()
开发者ID:d11,项目名称:rts,代码行数:11,代码来源:stacklessness.py

示例13: run

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
    def run(self):
        Thread.run(self)

        while not self.shouldShutDown:
            if not self.programsQueue.qsize() == 0:
                program = self.programsQueue.get_nowait()
                self.isFirstLoad = len(self.programLoader.pcbTable.pcbs) == 0
                self.programLoader.load(program)
                if self.isFirstLoad:
                    self.scheduler.setNextPcbToCpu()
开发者ID:ilaborde,项目名称:Sistemas-Operativos-Unqui,代码行数:12,代码来源:kernel.py

示例14: __init__

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
   def __init__(self,client,server):

       self.client = client
       self.server = server
    
       def startServer():
           self.server.start()
       
       serverThread = Thread(target = startServer, args = [])
       serverThread.run()
       self.client.run()
开发者ID:Jothecat,项目名称:DCIT_Project,代码行数:13,代码来源:Node.py

示例15: updateHash

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import run [as 别名]
 def updateHash(self, h):
     self.current_hash = h
     self.hash_string = h
     if self.hash_string == Utils.UNKNOWN_HASH:
         self.hash_string = self.UNKNOWN_BASIS_STRING
         self.value2_ctrl.SetLabel('')
     self.basis_ctrl.SetValue(self.hash_string)
     updateRobots = Thread(target=self._update_robohash)
     updateRobots.daemon = True
     updateRobots.run()
     self.Layout()
开发者ID:LucaLanziani,项目名称:FileRock-Client,代码行数:13,代码来源:__init__.py


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