2013-01-18 50 views
0

好吧,这是一个简单的问题,因为我真的不知道其所谓的..执行功能的同时运行脚本

说我有蟒蛇

if pattern in buffer: 
     while logme == "y": 
      logging.basicConfig(filename='hook.log',level=logging.DEBUG) 
      logging.debug("Pre-Encrypted: %s" % buffer) 
      print "Pre-Encrypted: %s" % buffer 
     else: 
      print "Pre-Encrypted: %s" % buffer 

一个循环我怎样才能使它所以当我在循环运行时按下P这样的键盘键并让它执行像暂停循环,退出或做任何事情的命令?不一样的命令行参数,但实际的程序运行时..

+0

我想你可能需要使用线程来保持循环的进行,同时在另一个线程中输入,因为'input()'和'raw_input()'都被阻塞了。 –

回答

1

你可以使用curses,这将是一个有点复杂。

围绕它的一个快速入侵将是在Python中拦截SIGINT(Ctrl-C,KeyboardInterrupt)。

def foo(): 
    try: 
    long_running_process() 
    catch KeyboardInterrupt: 
    deal_with_interrupt() 

除了违反有关Ctrl-C行为的期望之外,这也没有提供重新启动事物的明显方法。