reading from pipe

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

reading from pipe

Richard Lamboj-2

Hello,

is there any solution to catch if a pipe has closed? Maybe the signal modul?

For Simulation:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

while True:
        line = sys.stdin.readline()

        sys.stdout.write(line)
        sys.stdout.flush()

time cat /tmp/proxy.test | test.py

Solution:
if line == "":
        break

Kind Regards,

Richi
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: reading from pipe

Lutz Horn-4
Hi,

Richard Lamboj schrieb:
> is there any solution to catch if a pipe has closed? Maybe the signal modul?

Since sys.stdin is a file object, you can use sys.stdin.closed to check
if it has been closed.

Lutz
--
http://mail.python.org/mailman/listinfo/python-list