Python multiprocessing: Pass the shared resource along to children
Update 11 Aug '20: Turned out I misunderstood how multiprocessing module works! A Process can inherit resources created in the parent process scope but that does not include globals; ie if used_ids and used_ids_lock were defined in the block marked by if __name__ == '__main__' it would work (though not recommended). Python's documentation briefly touches upon this subject (see "Explicitly pass resources to child processes" section"). So, one correct way of structuring the code is: #!/usr/bin/env python ################################################################################ # simple tool to generate n random numbers. # # usage: # main.py N_RECORDS CONCURRENCY_STRATEGY:"t"|"p" CONCURRENCY_FACTOR:int # # N_RECORDS is an integer # CONCURRENCY_STRATEGY can only be either 't' or 'p' # CONCURRENCY_FACTOR is an integer (preferrably less than or equal to the no of # cores on the machine.) # # Examp...