Handle IOError: [Errno 32] Broken pipe

Will happen if piping through a pager like less, that closes
stdout before everything has been printed.

Related: #47
This commit is contained in:
Fabien Benureau 2015-12-18 22:31:49 +01:00
parent 2ba435126d
commit 5ca090668f

View File

@ -1,5 +1,19 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import sys
from pubs import pubs_cmd from pubs import pubs_cmd
pubs_cmd.execute()
try:
pubs_cmd.execute()
except IOError:
# stdout or stderr has been closed, cleaning up
try:
sys.stdout.close()
except IOError:
pass
try:
sys.stderr.close()
except IOError:
pass