Skip to main content

Fork your process like a boss

Project description

Fork your proccess like a boss

import forkme
import logging
import os
from time import sleep


logging.basicConfig(level=logging.DEBUG)


def main():
    print("Master proccess has PID: {0}".format(os.getpid()))
    forkme.fork(4)
    print(
        "Proceess #{id} has PID: {pid}".format(
            id=forkme.get_id(),
            pid=os.getpid()
        )
    )
    sleep(1)


if __name__ == '__main__':
    main()

This code makes 4 forks. When you try to run it you will see something like this

Master proccess has PID: 7437
INFO:forkme:Starting 4 processes
Proceess #2 has PID: 7440
Proceess #1 has PID: 7439
Proceess #3 has PID: 7441
Proceess #0 has PID: 7438
INFO:forkme:Child with PID: 7439 Number: 1 exited normally
INFO:forkme:Child with PID: 7441 Number: 3 exited normally
INFO:forkme:Child with PID: 7440 Number: 2 exited normally
INFO:forkme:Child with PID: 7438 Number: 0 exited normally

Forkme will be control forks. When subprocess will be killed or will exit with non-zero code it will be restarted immediately. e.g.:

Master proccess has PID: 7579
INFO:forkme:Starting 4 processes
Proceess #0 has PID: 7580
Proceess #1 has PID: 7581
Proceess #2 has PID: 7582
Proceess #3 has PID: 7583
WARNING:forkme:Child with PID: 7580 Number: 0 killed by signal 9, restarting
Proceess #0 has PID: 7584
INFO:forkme:Child with PID: 7581 Number: 1 exited normally
INFO:forkme:Child with PID: 7582 Number: 2 exited normally
INFO:forkme:Child with PID: 7583 Number: 3 exited normally
INFO:forkme:Child with PID: 7584 Number: 0 exited normally

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forkme-0.8.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

forkme-0.8-py2-none-any.whl (4.3 kB view details)

Uploaded Python 2

File details

Details for the file forkme-0.8.tar.gz.

File metadata

  • Download URL: forkme-0.8.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for forkme-0.8.tar.gz
Algorithm Hash digest
SHA256 fd81f1e9584ba688b17ef86ad9eccc8a8069c0bb85d3baacfb4a430c4c3aac50
MD5 a3f84fb12bef7133d1ead75b17c93260
BLAKE2b-256 3d58df07bdf1c2591e4807f5aa8f0fd88333bddb535bc519b5cd24b66dba916c

See more details on using hashes here.

File details

Details for the file forkme-0.8-py2-none-any.whl.

File metadata

File hashes

Hashes for forkme-0.8-py2-none-any.whl
Algorithm Hash digest
SHA256 0a42e453be9b47134070d978c96c243165564f6fcd9e11278fae2dab22e79ebe
MD5 c0ddc7ca5a6cd929001dcdc59a25dfbb
BLAKE2b-256 2c61d50afb88b347712ab1ae1da455751434f2a676d9e6eb75a8bdc76f6f8760

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page