Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mosquito/forkme
https://github.com/mosquito/forkme
fork posix python unix
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mosquito/forkme
- Owner: mosquito
- Created: 2016-08-08T17:47:10.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-23T13:13:00.000Z (over 6 years ago)
- Last Synced: 2025-01-19T06:46:28.126Z (6 days ago)
- Topics: fork, posix, python, unix
- Language: Python
- Size: 9.77 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
ForkMe
======Fork your proccess like a boss
.. code-block:: python
import forkme
import logging
import os
from time import sleeplogging.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 normallyForkme 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