Skip to content

Instantly share code, notes, and snippets.

Created March 17, 2011 21:45
What would you like to do?
Using Python's multiprocessing module, it's easy to create asynchronous subprocesses
#!/usr/bin/env python
# encoding: utf-8
import random
import time
import multiprocessing
if __name__ == '__main__':
"""Demonstration of GIL-friendly asynchronous development with Python's multiprocessing module"""
def process(instance):
total_time = random.uniform(0, 2)
print('Process %s : completed in %s sec' % (instance, total_time))
for i in range(10):
"""Create 10 non-blocking subprocesses that will have random runtimes"""
multiprocessing.Process(target=process, args=(i,)).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment