I have also had some broken pipe errors reported on Macs recently. Most I tracked down to print statements I had left in the code. Kovid has checked in a change that hopefully will fix this.
In any case, use:
Code:
from calibre.constants import DEBUG
"DEBUG" will be true if calibre is in debug mode.
I also tend to use a function called "debug_print". That adds a time to the log and only prints in debug mode. This is defined in calibre/devices/usbms/driver.py but I will sometimes copy it locally so I can customise if for the plugin.