Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # this is from The Python
- # Standard Library by example
- # ISBN13: 9780321767349
- import multiprocessing
- class MyFancyClass(object):
- def __init__(self, name):
- self.name = name
- def do_something(self):
- proc_name = multiprocessing.current_process().name
- print 'Doing something fancy in %s for %s!' % \
- (proc_name, self.name)
- def worker(q):
- obj = q.get()
- obj.do_something()
- if __name__ == '__main__':
- queue = multiprocessing.Queue()
- p = multiprocessing.Process(target=worker, args=(queue,))
- p.start()
- queue.put(MyFancyClass('Fancy Man'))
- # Wait for the worker to finish
- queue.close()
- queue.join_thread()
- p.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement