Skip to content

Instantly share code, notes, and snippets.

@schipiga
Created December 6, 2019 15:10
Show Gist options
  • Save schipiga/afdeba76825d2239c63c82a3a7ebc1e1 to your computer and use it in GitHub Desktop.
Save schipiga/afdeba76825d2239c63c82a3a7ebc1e1 to your computer and use it in GitHub Desktop.
import os
from functools import wraps
def waitpid(func):
cache = {}
@wraps(func)
def wrapper(pid, options):
try:
wpid, status = func(pid, options)
if wpid > 0:
cache[wpid] = status
except OSError as e:
if pid in cache:
return pid, cache[pid]
else:
raise e
else:
return wpid, status
return wrapper
os.waitpid = waitpid(os.waitpid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment