File: busywork.py

package info (click to toggle)
python-invoke 1.4.1%2Bds-0.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,704 kB
  • sloc: python: 11,377; makefile: 18; sh: 12
file content (23 lines) | stat: -rw-r--r-- 633 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
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)
    sys.stdout.write(out)
    sys.stdout.flush()
    err = "[{}] To err is human, to stderr is superhuman\n".format(i)
    sys.stderr.write(err)
    sys.stderr.flush()
    time.sleep(0.1)