簡體   English   中英

Python多進程導致腳本重新啟動

[英]Python multiprocess leads to restarting of script

我有一個函數注銷,導致超時並阻塞了我的腳本(由於服務器注銷后的服務器狀況)

要解決此問題,我嘗試從另一個進程調用注銷功能

def action(br, act):
    '''
        Push submit button on html page opened in browser, act = value of the button
        WARNING: The form is the first one!
    '''
    br.select_form(nr=0)
    br.submit(name=act, label=act)
def login(br):
    for x in range(0,5):
        action(br, 'ENT')
def logout(br):
    set_menu_root(br)
    action(br, 'ESC')

def safe_logout(br):
    try:
        proc = multiprocessing.Process(target=logout, args=(br))
        proc.start()
        time.sleep(1)
        proc.terminate()
    except:
        pass
def reboot(br):
    safe_logout(br)
    login(br)

但是由於某種原因,它首先按例外方式繼續無限循環,直到原始輸入為止,然后腳本突然重新啟動

print 'script start'
while True:
    set_menu_root(br)
    print 'Telegram test'
    menu = raw_input('set paramters of menu: ')
    if not go_to_menu(br, menu):
        print 'Menu not found'
        continue
    if len(menu) > 2:
        menu = menu[:-1]

    for n,x in enumerate(id_array):
        if x.value == menu:
            index = n
            break
    action(br, 'ENT')        
    para = get_para(br, menu_ends[index])
    for n,x in enumerate(para):
        print str(n) + ') ' + x

    i = int(raw_input('Select the value u want to map to parameter ' ) )
    set_para(br, menu_ends[index], para[i])
    raw_input("Check")
    reboot(br)

將我的腳本代碼放在

if __name__ == '__main__'

絕招

歸功於@tdihp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM