Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
Created January 20, 2014 08:24
Show Gist options
  • Save sp3c73r2038/8516721 to your computer and use it in GitHub Desktop.
Save sp3c73r2038/8516721 to your computer and use it in GitHub Desktop.
master/worker prefork process model.
#!/usr/bin/env python
from __future__ import unicode_literals, print_function
import os
from time import sleep
WORKERS = 3
_cnt = 0
while _cnt < WORKERS:
_cnt += 1
_pid = os.fork()
if _pid:
# master
print("pid {} forked".format(_pid))
else:
sleep(3600) # awesome work here
print("all worker forked!")
sleep(3600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment