2016-07-01 185 views
-1

我有一个文件名为test.pyWhile循环终端等待

test3 = 1000000000 
test = 0 
xtest = True 

def enable(): 
    while xtest: 
     test += 1 
     if test > test3: 
      test3 += test3 * 3 

和一个名为testit.py的文件。

import test 
test.enable() 

当我运行python testit.py我的终端保持未使用状态,我如何避免终端等待?

+2

看起来像你的循环将永远持续下去......但是如果这就是你想要的,你可以运行'python testit.py&'来把在后台工作(取决于你的shell)。 – mgilson

+2

这会吃掉整个CPU。您应该考虑在某处添加睡眠 –

+0

如果您的终端在预期时未返回提示,则说明您有问题。 – Jeremy

回答

1

我不确定你的问题是什么,但对我来说,看起来像一个无限循环。 xtest是负责停止循环的变量,从未在循环内设置为False。

0

简单我想在后台运行它对不起我的英文不好, 如果我想通过shell启用必须做什么?

import cmd 
import operator 
import test 


class Ec(cmd.Cmd): 
    prompt = "testshell$ " 
    intro = "Welcome to the testshell shell, type `help` to get started." 

    def do_test(self, line): 
     test.enable() 

    #function 
    #function 

    def do_help(self, line): 
     print """ 
       test - to enable it 
       +++++++++++++++++++ 



       """ 

if __name__ == "__main__": 
    Ec().cmdloop() 

当我运行它上面我得到 欢迎testshell壳型help上手。 testshell $当它的类型测试仍在等待并且不返回到shell菜单

+0

这看起来应该是问题的一部分。请删除它作为答案,而是编辑问题,以完全解释你在做什么,出了什么问题。 – Blckknght