Created
September 6, 2016 07:42
-
-
Save oglops/962a4bc9bbc3ca3872f003aa3f37452e to your computer and use it in GitHub Desktop.
test multiprocessing env var
This file contains 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
from random import randint | |
from time import sleep | |
import os | |
def slow_func( ): | |
print 'in slow_func, start processing: %s' % os.environ['SHOT'] | |
sleep(randint(2,7)) | |
print 'in slow_func, done processing: %s' % os.environ['SHOT'] |
This file contains 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 os | |
from libA import slow_func | |
def worker(*args): | |
"""thread worker function""" | |
name = multiprocessing.current_process().name | |
print 'Worker:', name | |
os.environ['SHOT']=name | |
slow_func() | |
return | |
if __name__ == '__main__': | |
jobs = [] | |
os.environ['SHOT'] = 'set_in_main' | |
for shot in ['abc010','abc020','abc030','abc040','abc050']: | |
p = multiprocessing.Process(name=shot,target=worker, args=(shot,)) | |
jobs.append(p) | |
p.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment