File: stdio_checks.py

package info (click to toggle)
python-mitogen 0.3.29-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,680 kB
  • sloc: python: 24,266; sh: 198; makefile: 74; perl: 19; ansic: 18
file content (31 lines) | stat: -rw-r--r-- 674 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
24
25
26
27
28
29
30
31
import fcntl
import os
import sys


def _shout_stdout_py3(size):
    nwritten = sys.stdout.write('A' * size)
    return nwritten


def _shout_stdout_py2(size):
    shout = 'A' * size
    nwritten = 0
    while nwritten < size:
        nwritten += os.write(sys.stdout.fileno(), shout[-nwritten:])
    return nwritten


def shout_stdout(size):
    if sys.version_info > (3, 0):
        return _shout_stdout_py3(size)
    else:
        return _shout_stdout_py2(size)


def file_is_blocking(fobj):
    return not (fcntl.fcntl(fobj.fileno(), fcntl.F_GETFL) & os.O_NONBLOCK)


def stdio_is_blocking():
    return [file_is_blocking(f) for f in [sys.stdin, sys.stdout, sys.stderr]]