Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys.stdout.flush() crashes when closed #3

Open
anarcat opened this issue May 23, 2014 · 0 comments
Open

sys.stdout.flush() crashes when closed #3

anarcat opened this issue May 23, 2014 · 0 comments

Comments

@anarcat
Copy link
Owner

anarcat commented May 23, 2014

if bup is called somewhat with a weird stdout, for example if redirected to /dev/null (iirc), it will crash with:

19:31 <anarcat>     sys.stdout.flush()
19:31 <anarcat> IOError: [Errno 9] Bad file descriptor
19:31 <anarcat>   File "/usr/lib/bup/cmd/bup-index", line 89, in update_index

this is of course related to #2.

here's a workaround:

diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py
index b7fe8f1..3eedb31 100755
--- a/cmd/index-cmd.py
+++ b/cmd/index-cmd.py
@@ -87,7 +87,11 @@ def hashgen(name):
                                                  exclude_rxs=exclude_rxs):
         if opt.verbose>=2 or (opt.verbose==1 and stat.S_ISDIR(pst.st_mode)):
             sys.stdout.write('%s\n' % path)
-            sys.stdout.flush()
+            try:
+                sys.stdout.flush()
+            except IOError:
+               # probably stdout is closed, ignore
+               pass
             elapsed = time.time() - index_start
             paths_per_sec = total / elapsed if elapsed else 0
             qprogress('Indexing: %d (%d paths/s)\r' % (total, paths_per_sec))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant