Last active
August 25, 2019 15:29
-
-
Save santiagosilas/3a62611007379c2ae22a1773e152d97b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import multiprocessing | |
| import time | |
| class Monitor(multiprocessing.Process): | |
| def __init__(self, ): | |
| multiprocessing.Process.__init__(self) | |
| self.exit = multiprocessing.Event() | |
| def run(self): | |
| while not self.exit.is_set(): | |
| time.sleep(0.5) | |
| print('working..') | |
| print("Done!") | |
| def terminate(self): | |
| print("Bye!") | |
| self.exit.set() | |
| if __name__ == "__main__": | |
| monitor = Monitor() | |
| monitor.start() | |
| print("Waiting for a while") | |
| time.sleep(3) | |
| monitor.terminate() | |
| monitor.join() | |
| time.sleep(3) | |
| print("Child process state: %d" % monitor.is_alive()) | |
| print('Process exit code: %d' % monitor.exitcode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment