Created
March 14, 2019 15:08
-
-
Save bbayles/3364882fc50d355455594f2bb29041b9 to your computer and use it in GitHub Desktop.
Multiprocessing Freeze Support Test
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 sys | |
| print('Arguments were', repr(sys.argv)) | |
| from argparse import ArgumentParser | |
| import multiprocessing | |
| from random import randrange | |
| from time import sleep | |
| def talk(x): | |
| sleep(x) | |
| print('Slept for {} seconds'.format(x)) | |
| def main(): | |
| n = 10 | |
| arg_list = [randrange(n) for x in range(n)] | |
| with multiprocessing.Pool() as pool: | |
| all_results = pool.imap(talk, arg_list) | |
| for result in all_results: | |
| pass | |
| if __name__ == '__main__': | |
| multiprocessing.freeze_support() | |
| argument_parser = ArgumentParser() | |
| args = argument_parser.parse_args() | |
| # multiprocessing.set_start_method('spawn') | |
| multiprocessing.set_start_method('forkserver') | |
| main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment