File: busywork.py

package info (click to toggle)
python-invoke 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,856 kB
  • sloc: python: 15,986; makefile: 24
file content (21 lines) | stat: -rw-r--r-- 623 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""
Program that just does busywork, yields stdout/stderr and ignores stdin.

Useful for measuring CPU usage of the code interfacing with it without
expecting the test environment to have much of anything.

Accepts a single argv argument, which is the number of cycles to run.
"""

import sys
import time


num_cycles = int(sys.argv[1])

for i in range(num_cycles):
    out = "[{}] This is my stdout, there are many like it, but...\n".format(i)
    print(out, file=sys.stdout, flush=True)
    err = "[{}] To err is human, to stderr is superhuman\n".format(i)
    print(out, file=sys.stderr, flush=True)
    time.sleep(0.1)