Python发送命令

Python发送命令

问题描述:

我试图发送一个End命令到这行代码的末尾。 我搜索无处不在,没能找到一个有价值的答案..Python发送命令

if args.time: 
    def stopwatch(seconds): 
     start = time.time() 
     time.clock()  
     elapsed = 0 
     while elapsed < seconds: 
      elapsed = time.time() - start 
      print "Sending for(900) Seconds: %f, seconds count: %02d" % (time.clock() , elapsed) 
      time.sleep(1) 

stopwatch(5) 

婉婷送一些一Control C排序是来阻止它,而不 退出程序。

您可以使用control-c。

你只需要赶上KeyboardInterrupt例外。

try: 
    # your loop code here 
except KeyboardInterrupt: 
    # do whatever you want when user presses ctrl+c 

你想赶上一个KeyboardInterrupt

if args.time: 
    def stopwatch(seconds): 
     start = time.time() 
     time.clock()  
     elapsed = 0 
     while elapsed < seconds: 
      try: 
       elapsed = time.time() - start 
       print "Sending for(900) Seconds: %f, seconds count: %02d" % (time.clock() , elapsed) 
       time.sleep(1) 
      except KeyboardInterrupt: break 

    stopwatch(5)