reading from pipe

R

Richard Lamboj

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
 
L

Lutz Horn

Hi,

Richard said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top