import fcntl
import os
import sys
fd = sys.stdin.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
try:
    print(sys.stdin.read())
except:
    print('No input')
Find out if there is input from a pipe or not in Python?