Linux Blocking vs. non Blocking Serial Read

The code you mention is IMO poorly coded and commented. That code does not conform to POSIX practices for portability as described in Setting Terminal Modes Properly and Serial Programming Guide for POSIX Operating Systems. That code does not mention that it uses non-canonical (aka raw) mode, and reuses the “blocking” and “nonblocking” terminology to … Read more

A non-blocking read on a subprocess.PIPE in Python

fcntl, select, asyncproc won’t help in this case. A reliable way to read a stream without blocking regardless of operating system is to use Queue.get_nowait(): import sys from subprocess import PIPE, Popen from threading import Thread try: from queue import Queue, Empty except ImportError: from Queue import Queue, Empty # python 2.x ON_POSIX = ‘posix’ … Read more