I need to process signals in my code, and I use global to share states between functions:
exit = False def setup_handler(): signal.signal(signal.SIGTERM, handler) def handler(num, frame): global exit exit = True def my_main(): global exit while not exit: do_something() if __name__ == '__main__': setup_handler() my_main()
Is there a way to avoid a global variable in this case? What is the best way to share state in this case?
source share