diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-03-07 16:43:58 -0500 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-03-07 16:43:58 -0500 |
commit | c2051f1fa112c1dc2b28d65e597eda85cb2e56ea (patch) | |
tree | 4740415dcb2c2ae56d4cbe11616cdc02922b6661 /Lib/test/memory_watchdog.py | |
parent | 9979ecb3f2a13f92284f6d1d6e419101d48ec211 (diff) | |
parent | 5ac5e0bf7238d635e4f2079d13083c61a886d9de (diff) | |
download | cpython-c2051f1fa112c1dc2b28d65e597eda85cb2e56ea.tar.gz |
Merge: #14645: Generator now emits correct linesep for all parts.
Previously the parts of the message retained whatever linesep they had on
read, which means if the messages weren't read in univeral newline mode, the
line endings could well be inconsistent. In general sending it via smtplib
would result in them getting fixed, but it is better to generate them
correctly to begin with. Also, the new send_message method of smtplib does
not do the fixup, so that method is producing rfc-invalid output without this
fix.
Diffstat (limited to 'Lib/test/memory_watchdog.py')
-rw-r--r-- | Lib/test/memory_watchdog.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/memory_watchdog.py b/Lib/test/memory_watchdog.py new file mode 100644 index 0000000000..88cca8d323 --- /dev/null +++ b/Lib/test/memory_watchdog.py @@ -0,0 +1,28 @@ +"""Memory watchdog: periodically read the memory usage of the main test process +and print it out, until terminated.""" +# stdin should refer to the process' /proc/<PID>/statm: we don't pass the +# process' PID to avoid a race condition in case of - unlikely - PID recycling. +# If the process crashes, reading from the /proc entry will fail with ESRCH. + + +import os +import sys +import time + + +try: + page_size = os.sysconf('SC_PAGESIZE') +except (ValueError, AttributeError): + try: + page_size = os.sysconf('SC_PAGE_SIZE') + except (ValueError, AttributeError): + page_size = 4096 + +while True: + sys.stdin.seek(0) + statm = sys.stdin.read() + data = int(statm.split()[5]) + sys.stdout.write(" ... process data size: {data:.1f}G\n" + .format(data=data * page_size / (1024 ** 3))) + sys.stdout.flush() + time.sleep(1) |