Skip to main content

ForkMe

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

Metadata

Release files for forkme 0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for forkme 0.11
File Size Uploaded
forkme-0.11.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for forkme 0.11
File Interpreter ABI Platform
forkme-0.11-py2-none-any.whl Python 2 none any Details

Total release size: 7.1 kB

Release files / forkme-0.11.tar.gz

Download URL forkme-0.11.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2f2347e14ed9d0ce42eeadc7a88cf0824eb22324202b6f5c6d213be3b02cc8f4
BLAKE2b-256 checksum
How to use checksums
133c9e2411442e003a722fcc2a80165b23e8d9c6bfeb6a99a82b8231768c857c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / forkme-0.11-py2-none-any.whl

Download URL forkme-0.11-py2-none-any.whl
Size 4.3 kB
Tags Python 2
SHA-256 checksum
How to use checksums
feee997d6ec4f4e2b73a67b4f45e31c12e5f876e53ec548a1ac743c4457d582b
BLAKE2b-256 checksum
How to use checksums
a13971b43dfdc2d976709f8bfcb44a80bf4edf368dbb83acd6478c347947fd53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.11 This release

2 release files

0.10

1 release file

0.8

2 release files

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page