5

I try to debug a python script that interfaces MPD using python-mpd2.

When the script tries to perform an action after being idle for a couple of hours, it terminates with an exception (BrokenPipeError in Python 3, socket.pipe in Python 2 - [Errno 32] Broken pipe in both cases).

The fact that the broken pipe only appears after hours of idle time makes debugging extremely slow.

Is there a way to provoke the same behavior - a broken pipe to mpd - manually?

Marcel
  • 1,114
  • 1
  • 14
  • 28
  • That's quite typical behavior, actually; connection gets broken. Why can't you just catch the exception and reconnect? – TNW Jan 11 '16 at 12:38
  • It might be typical but it's not that easy :) you can read more on my efforts here: http://stackoverflow.com/questions/34718208/catch-broken-pipe-in-python-2-and-python-3, http://stackoverflow.com/questions/34463087/raise-exception-in-python-2-x-and-3-x and https://github.com/Mic92/python-mpd2/issues/64. However, I am quite close to a solution. But - as I point out in my question - testing is quite time consuming and I am looking for a way to speed up this process. – Marcel Jan 11 '16 at 12:47
  • Then you might try to disconnect the network - would it work for you? – TNW Jan 11 '16 at 12:58
  • 2
    Stop the MPD service / daemon (forcibly if necessary)? – EightBitTony Jan 11 '16 at 13:04
  • @TNW well, the mpd server runs on localhost but sometimes on a remote pc (a raspberry pi) so disconnecting the network probably wouldn't work. – Marcel Jan 11 '16 at 13:07
  • @EightBitTony This would be a possibility. But not knowing much about pipes and sockets I don't know if a terminated service appears to be the same as a broken pipe for the python script. Also I wondered if there was a more gentle way... but if there is none... – Marcel Jan 11 '16 at 13:16
  • @Marcel not sure either, give it a shot with a graceful stop of the daemon and see how the pipe behaves, if that doesn't work, just kill -9 the daemon, as long as it's not writing to any files, kill -9 shouldn't be too harsh on it ;) – EightBitTony Jan 11 '16 at 13:47

1 Answers1

2

according to man 7 signal

SIGPIPE 13 Term Broken pipe: write to pipe with no readers

so the answer should be

kill -13 1234

(1234 being your PID)

(broken pipe are bad luck ? )

Archemar
  • 31,183
  • 18
  • 69
  • 104