sigpipe

IOError: [Errno 32] Broken pipe: Python

允我心安 提交于 2019-11-27 10:46:39
I have a very simple Python 3 script: f1 = open('a.txt', 'r') print(f1.readlines()) f2 = open('b.txt', 'r') print(f2.readlines()) f3 = open('c.txt', 'r') print(f3.readlines()) f4 = open('d.txt', 'r') print(f4.readlines()) f1.close() f2.close() f3.close() f4.close() But it always says: IOError: [Errno 32] Broken pipe I saw on the internet all the complicated ways to fix this, but I copied this code directly, so I think that there is something wrong with the code and not Python's SIGPIPE. I am redirecting the output, so if the above script was named "open.py", then my command to run would be:

IOError: [Errno 32] Broken pipe: Python

半世苍凉 提交于 2019-11-26 17:57:50
问题 I have a very simple Python 3 script: f1 = open('a.txt', 'r') print(f1.readlines()) f2 = open('b.txt', 'r') print(f2.readlines()) f3 = open('c.txt', 'r') print(f3.readlines()) f4 = open('d.txt', 'r') print(f4.readlines()) f1.close() f2.close() f3.close() f4.close() But it always says: IOError: [Errno 32] Broken pipe I saw on the internet all the complicated ways to fix this, but I copied this code directly, so I think that there is something wrong with the code and not Python's SIGPIPE. I am

How to prevent SIGPIPEs (or handle them properly)

爱⌒轻易说出口 提交于 2019-11-25 23:20:34
问题 I have a small server program that accepts connections on a TCP or local UNIX socket, reads a simple command and, depending on the command, sends a reply. The problem is that the client may have no interest in the answer sometimes and exits early, so writing to that socket will cause a SIGPIPE and make my server crash. What\'s the best practice to prevent the crash here? Is there a way to check if the other side of the line is still reading? (select() doesn\'t seem to work here as it always