Skip to content

Instantly share code, notes, and snippets.

@jiafangtao
Created December 14, 2023 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiafangtao/4b5f87c0b251b620fe6f3ea1209939cc to your computer and use it in GitHub Desktop.
Save jiafangtao/4b5f87c0b251b620fe6f3ea1209939cc to your computer and use it in GitHub Desktop.
random output to stdout or stderr
import sys
import time
import random
print(f"hello from {sys.argv[0]}")
out = 0
err = 0
while out < 10 and err < 10:
choice = random.randint(0, 1)
if choice > 0:
sys.stdout.write(f'out {out}...\n')
sys.stdout.flush()
out += 1
else:
sys.stderr.write(f'err {err}...\n')
sys.stderr.flush()
err += 1
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment