Created
March 16, 2018 03:06
-
-
Save youngsofun/4fa0ee2114498f8ea23f724d2f3239e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
import threading | |
import time | |
import os | |
import psutil | |
import sys | |
import errno | |
def worker(): | |
print('warker start') | |
time.sleep(10) | |
print('worker exit') | |
os._exit(3) | |
#sys.exit(3) | |
#return 3 | |
def check_mem(): | |
time.sleep(5) | |
print('check_mem end') | |
os._exit(3) | |
def worker2(): | |
print('warker start') | |
t = threading.Thread(target=check_mem) | |
t.daemon = True | |
t.start() | |
while True: | |
time.sleep(10) | |
print('worker exit') | |
def executor(): | |
proc = multiprocessing.Process(target=worker2) | |
proc.daemon = True | |
proc.start() | |
pid = proc.pid | |
print('work pid', pid) | |
ps = psutil.Process(pid) | |
while not (ps.status() == psutil.STATUS_ZOMBIE or not ps.is_running()): | |
print('working, ', ps.status()) | |
time.sleep(1) | |
proc.join(1) | |
print('exit code', proc.exitcode) | |
try: | |
os.waitpid(pid, os.WNOHANG) | |
except OSError as e: | |
if e.errno == errno.ECHILD: | |
print("errno.ECHILD") | |
else: | |
logger.exception('process termination fail: ', e.message) | |
executor() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reserved exit codes:
are-there-any-standard-exit-status-codes-in-linux
https://shapeshed.com/unix-exit-codes/