getProcessing()函数执行不会停止

时间:2015-06-01 22:08:53

标签: python

我在下面的代码中显示了一个选项菜单。

如果用户选择选项2,它会执行函数getProcessing(),并且工作正常。

唯一的问题是,当执行getProcessing函数时,我想停止执行此函数并再次显示选项菜单。但这不起作用,getProcessing()函数执行不会停止。

我试图把返回False,但仍然无效。

你知道为什么会发生这种情况吗?

def getProcessing():
    # from processing.py file import createmrjob function
    from processing import createmrjob
    return False

def nav():
    print ""
    while True:
        response_options = {'1': Choice(msg="User Managment", callback=userManagment), '2': Choice(msg="Processing Files", callback=getProcessing)}
        result = make_choice(response_options)
        if result is None:
            print "Selected option not available."
            print ""
        else:
            result.callback()

def make_choice(optiontable):
    for resp, choiceobj in (sorted(optiontable.items())):   
        print("{} - {}".format(resp, choiceobj.msg))
    print ""
    usr_resp = raw_input("Select an option: ")
    print ""
    return optiontable.get(usr_resp, None)

当下面的函数中的状态为= COMPLETED时,我想显示消息"已完成的作业",但我得到的是行print status.state,因此它始终显示消息&# 34;已完成"并且不要退出此循环以显示"已完成的工作"。

def createmrjob(dict):  
    emr = boto.emr.connect_to_region('us-east-1')
    print ""
    bucket = dict['bucket']
    step = StreamingStep(name='Max Temperature',
    mapper=dict['mapper'],
    reducer=dict['reducer'],
    input=dict['datafile'],
    output='s3n://'+bucket+'/uploadedfiles/')
    jobid = emr.run_jobflow(name="Data Processing", 
    log_uri="s3://"+bucket+"/uploadedfiles/erm_logs/",
    steps=[step],
    num_instances = 1,
    )

    print "Job flow submited with success, waiting for job flow to complete..."

    status = emr.describe_jobflow(jobid)    
    print status.state
    while status.state != 'COMPLETED' or status.state != 'FAILED':      
        status = emr.describe_jobflow(jobid)
        print status.state
    print ""
    print "Job status:" + str(status.state)
    print ""
    print "Completed Job"
    print ""

0 个答案:

没有答案