Python-brisa 可在 Eclipse 中运行,但不能在 shell 中运行
下一个 python-brisa 代码可以在 Eclipse 中运行,但如果我从 shell 执行它,就会卡住。我认为问题出在reactor.main()中。因为如果我注释它并创建一个无限循环,该程序将在 Eclipse 和 shell 中运行。知道如何修复它吗?
python版本是2.6.6,我正在使用Debian测试(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()
The next python-brisa code works in Eclipse but gets stuck if I execute it from the shell. I think that the problem is in reactor.main(). Because if I comment it and I create a infinite loop the program works in Eclipse and in the shell. Any idea of how can I fix it?
The python version is the 2.6.6 and I am using 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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了“错误”。解决方案是替换该行:
我
不确定,但也许原因可以在这个解释中:
如果有人有其他
解释,我将不胜感激如果评论的话。
I found the "error". The solution was substitute the line:
by
I am not sure but maybe the reason of this can be in this explanation:
http://pydev.org/faq.html#why_raw_input_input_does_not_work_correctly
If someone has another explanation I will grateful if comment it.