Created
April 27, 2018 06:57
-
-
Save JaredCE/55ba03da3af8a041d6564aa903471637 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 random | |
import string | |
class doThis: | |
def __init__(self): | |
print('init') | |
def get_array(self): | |
arr = [random.random() for _ in range(100)] | |
return [arr] | |
def start_job(self): | |
arr = self.get_array() | |
# self.do_stuff(arr) | |
process_workers = round(len(arr)/10) | |
pool = multiprocessing.Pool(processes=process_workers) | |
print(pool.map(self.do_stuff, arr)) | |
# jobs = [] | |
# p = multiprocessing.Process(target=self.do_stuff, args=([arr])) | |
# jobs.append(p) | |
# p.start() | |
def get_info(self, id): | |
name = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6)) | |
return {'id': id, 'org': {'id': random.randint(0,9), 'name': (name)}} | |
def create_filename(self, obj): | |
return str(obj['id']) + '-' + str(obj['org']['name'] + '.pdf') | |
def do_stuff(self, arr): | |
print(arr) | |
proc_name = multiprocessing.current_process().name | |
print(proc_name) | |
print('called') | |
for invoice in arr: | |
obj = self.get_info(invoice) | |
# print('{}'.format(obj)) | |
filename = self.create_filename(obj) | |
if __name__ == '__main__': | |
x = doThis() | |
x.start_job() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment