Untitled

 avatar
Majeric
python
3 years ago
1.3 kB
5
Indexable
#first_file.py

from time import sleep
import second_file, threading

def monitor_for_false():
        print("[first_file]monitor_for_false: start") 

        sleep(1) #give time for multiple threads to start

        work_being_done = True
        while second_file.work_being_done:
                pass
        print("[first_file]monitor_for_false: end") 


def do_work_and_update_ui():
        user_interface = threading.Thread(target=monitor_for_false)
        work = threading.Thread(target= second_file.some_big_job)
        user_interface.start()
        work.start()

if __name__ == "__main__":
        do_work_and_update_ui()
        
#===========================================================================================
# second_file.py 

from time import sleep

work_being_done = False

def some_big_job():
        global work_being_done
        print("[first_file]some_big_job: start") 
        work_being_done = True

        for x in range(0, 10):
            print("[second_file]some_big_job:" + str(work_being_done) + ":" + str(x))
            sleep(1)


        #I want to modify *THAT* variable so, that the thread will stop.
        print("[second_file]some_big_job: end") 
        work_being_done = False