import locale
import sys

from py3status.core import Py3statusWrapper

try:
    from setproctitle import setproctitle
    setproctitle('py3status')
except ImportError:
    pass


def main():
    try:
        locale.setlocale(locale.LC_ALL, '')
    except locale.Error:
        print('No locale available')
        sys.exit(2)

    py3 = None
    try:
        py3 = Py3statusWrapper()
        py3.setup()
    except KeyboardInterrupt:
        if py3:
            py3.notify_user('Setup interrupted (KeyboardInterrupt).')
        sys.exit(0)
    except Exception as e:
        if py3:
            py3.report_exception('Setup error')
        else:
            # we cannot report this Exception
            raise e
        sys.exit(2)

    try:
        py3.run()
    except Exception:
        py3.report_exception('Runtime error')
        sys.exit(3)
    except KeyboardInterrupt:
        pass
    finally:
        py3.stop()
        sys.exit(0)


if __name__ == '__main__':
    main()

@@ -171,16 +171,128 @@
   pass%0A%0A
+try:%0A    # python3%0A    IOPipeError = BrokenPipeError%0Aexcept NameError:%0A    # python2%0A    IOPipeError = IOError%0A%0A
 %0Adef mai
@@ -511,32 +511,46 @@
 tup()%0A    except
+ (IOPipeError,
  KeyboardInterru
@@ -543,32 +543,33 @@
 eyboardInterrupt
+)
 :%0A        if py3
@@ -620,29 +620,8 @@
 pted
- (KeyboardInterrupt).
 ')%0A 
@@ -858,16 +858,74 @@
 3.run()%0A
+    except (IOPipeError, KeyboardInterrupt):%0A        pass%0A
     exce
@@ -1008,51 +1008,8 @@
 (3)%0A
-    except KeyboardInterrupt:%0A        pass%0A
     

handle i3bar broken pipe and IO errors, fixes #538