Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python
- import time
- import multiprocessing as mp
- class Job(object):
- def __init__(self, target, *a, **kw):
- self.target = target
- self.args = a
- self.kwargs = kw
- def parallelize(jobs):
- """
- Args:
- jobs (list): list of the jobs to run. with all its params
- """
- procs = [mp.Process(target=job.target, args=job.args, kwargs=job.kwargs) for job in jobs]
- for p in procs:
- p.start()
- for p in procs:
- p.join()
- def dummy(*a, **kw):
- print a
- time.sleep(1)
- print kw
- def main():
- parallelize([Job(dummy) for i in range(2)])
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement