2016-07-01 119 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