def isInteractivePosix(): try: import posix tty = open("/dev/tty") tpgrp = posix.tcgetpgrp(tty.fileno()) pgrp = posix.getpgrp() tty.close() return (tpgrp == pgrp) finally: return False
def is_interactive(): '''Return true if run from an interactive session.''' try: tty = open('/dev/tty') tpgrp = posix.tcgetpgrp(tty.fileno()) pgrp = posix.getpgrp() tty.close() return (tpgrp == pgrp) except IOError: return False
def is_foreground(): tpgrp = posix.tcgetpgrp(posix_tty_fd) pgrp = posix.getpgrp() return tpgrp == pgrp