-
- Downloads
Better error message if file objects aren't seekable
As reported by teor, stem.descriptor's parse_file() function cannot accept stdin... https://trac.torproject.org/projects/tor/ticket/23859 The trouble is that not all file objects in python are seekable. I'd *like* to handle address this transparently by buffering the content... try: descriptor_file.tell() except IOError: # file's not seekable, wrapping in a buffer that is descriptor_file = io.BytesIO(descriptor_file.read()) This works great if our stream has content... % cat my_descriptors | python demo.py *But* hangs indefinitely if no EOF is present in the stream. % python demo.py <= hangs Turns out non-blocking, platform independent reading of streams like stdin is pretty tricky... http://eyalarubas.com/python-subproc-nonblock.html As such simply providing callers with a more descriptive exception. If they know their stream won't block *they* can add the above wrapper to provide us with a seekable file object.
Please register or sign in to comment