Skip to content

Instantly share code, notes, and snippets.

Embed
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)
time.sleep(total_time)
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
You can’t perform that action at this time.