为什么helper线程没有在这个python脚本中退出?

时间:2017-09-21 10:44:23

标签: python multithreading python-3.x global-variables python-multithreading

我有三个文件:

helper.py

from globalvariables import *

global exit_signal
global exited_signal

def helperstart():

    global exited_signal

    while True:
        if exit_signal is True:
            exited_signal = True
            print ('Exiting from helper thread')
            return

main.py

from globalvariables import *
import threading
import helper

global exit_signal
global exited_signal

def mainstart():

    global exit_signal

    helper_thread = threading.Thread(target = helper.helperstart)
    input ('Press <enter> to start the thread')
    helper_thread.start()
    input ('Press <enter> to end the thread')
    exit_signal = True

    # check if helper has exited
    if exited_signal is True:
        print ('Helper exited successfully')

if __name__ == '__main__':
    mainstart()

globalvariables.py

exit_signal = False
exited_signal = False

main.py开始,exit_signal的值应编辑为True。这应该使助手线程退出。但它并没有退出。我已经尝试从exit_signal函数打印helperstart()的值,并且它一直显示为False。因此,main.py无法正确编辑变量。请帮我弄清楚原因。

0 个答案:

没有答案