Skip to content

Instantly share code, notes, and snippets.

@despiegk
Created September 19, 2016 10:00
Show Gist options
  • Save despiegk/912149a62687e5004258ae6bd50bb56e to your computer and use it in GitHub Desktop.
Save despiegk/912149a62687e5004258ae6bd50bb56e to your computer and use it in GitHub Desktop.
import os
import sys
import time
import traceback
rpipe, wpipe = os.pipe()
pid = os.fork()
if pid == -1:
raise TestError("Failed to fork() in prepare_test_dir")
if pid == 0:
# Child -- do the copy, print log to pipe and exit
try:
os.close(rpipe)
os.dup2(wpipe, sys.stdout.fileno())
os.dup2(wpipe, sys.stderr.fileno())
os.close(wpipe)
counter = 0
while True:
print(counter)
counter += 1
time.sleep(1)
sys.stdout.flush()
sys.stderr.flush()
if counter == 10:
break
except:
traceback.print_exc(20, sys.stderr)
finally:
sys.stdout.flush()
sys.stderr.flush()
os._exit(1)
else:
os.close(wpipe)
# _, status = os.waitpid(pid, 0)
from IPython import embed
print("DEBUG NOW 8888")
embed()
raise RuntimeError("stop debug here")
outf = os.fdopen(rpipe)
copy_log = outf.read()
# return os.WEXITSTATUS(status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment