0
下一個python-brisa代碼在Eclipse中工作,但如果我從shell執行它,它會卡住。我認爲這個問題在reactor.main()中。因爲如果我評論它並創建一個無限循環,該程序將在Eclipse和shell中工作。任何想法如何解決它?Python-brisa在Eclipse中工作,但不在shell中
Python版本是2.6.6,我使用的是Debian Testing(wheezy)。
#!/usr/bin/env python
from brisa.core.reactors import install_default_reactor
from brisa.core.threaded_call import run_async_function
reactor = install_default_reactor()
import thread
import sys
from brisa.upnp.control_point.control_point import ControlPoint
class CommandLineCtrlPoint(ControlPoint):
def __init__(self):
ControlPoint.__init__(self)
self.running = False
self.commands = {'option1': 'option1',
'option2': 'option2',
'option3' :'option3',
'help': self._help}
def run(self):
try:
self.running = True
reactor.add_after_stop_func(self.stop)
thread.start_new_thread(self._handle_cmds,())
reactor.main()
# while(True):
# pass
except Exception, e:
print e
def _help(self):
help = 'commands: '
for k in self.commands.keys():
help += k + ', '
print help[:-2]
def _handle_cmds(self):
try:
while self.running:
command = str(raw_input('>>>'))
try:
print command
self.commands[command]()
except KeyError:
print 'invalid command, try help'
command = ''
except Exception, e:
print e
def main():
print "Test Program\n"
cmdline = CommandLineCtrlPoint()
cmdline.run()
if __name__ == "__main__":
main()