[MERGE] Bugfix #87178: don't do sys.stdout.flush() outside exception wrapper

Alexander Belchenko bialix at ukr.net
Fri Jun 22 06:57:39 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John Arbash Meinel пишет:
> Alexander Belchenko wrote:
>> This patch fixes problem described in bug report
>> https://bugs.launchpad.net/bzr/+bug/87178.
> 
>> This patch simply revert changes made by Ian
>> in revision 2394.2.6 (merged to 2448).
> 
>> [µ]
> 
> ------------------------------------------------------------------------
> 
> === modified file 'bzrlib/commands.py'
> --- bzrlib/commands.py	2007-06-06 11:06:04 +0000
> +++ bzrlib/commands.py	2007-06-21 09:48:32 +0000
> @@ -713,11 +713,9 @@
> 
>  def run_bzr_catch_errors(argv):
>      try:
> -        try:
> -            return run_bzr(argv)
> -        finally:
> -            # do this here inside the exception wrappers to catch EPIPE
> -            sys.stdout.flush()
> +        return run_bzr(argv)
> +        # do this here inside the exception wrappers to catch EPIPE
> +        sys.stdout.flush()
>      except (KeyboardInterrupt, Exception), e:
>          # used to handle AssertionError and KeyboardInterrupt
>          # specially here, but hopefully they're handled ok by the
> logger now
> 
> 
> -1.
> 
> You are doing 'sys.stdout.flush()" *after* 'return X', which means it
> will never be run.

I just look at code of bzr 0.15 and before. It contains code as in my patch.
I.e. in earlier versions of bzr this statement is never invoked at all.

Furthermore, decorator @display_command do all needed stuff to flush stdout,
so I strictly think we should remove this flush from run_bzr_catch_errors.

> You could instead do:
> 
> retval = run_bzr(argv)
> sys.stdout.flush()
> return retval

No, if I do this I'm again will have problems with Errno.22 on Windows.
Because of reason you describe below:

> We would want to make sure that still works, because Windows gives some
> strange results when you try to 'sys.stdout.flush()' after the pipe is
> broken. I thought we fixed the EPIPE handler to handle that exception.
> 
> Note, we could also be running into problems because the 'bzr' main
> script does:
> 
>     exit_val = bzrlib.commands.main(sys.argv)
>     sys.exit_func()
>     try:
>         sys.stdout.flush()
>         sys.stderr.flush()
>     except IOError, e:
>         import errno
>         if sys.platform != 'win32' or e.errno != errno.EINVAL:
>             raise
>     os._exit(exit_val)
> 
> But that looks like it is also trying to handle EINVAL at that level.

Yes, I know, because I add this exception handler.

[µ]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGe2TTzYr338mxwCURAnTqAJkBTK3l1g2vxT6i2qgyAmbVD1R48QCfbYVs
an/2NBkjTjliRji4gqurGaA=
=NfZC
-----END PGP SIGNATURE-----



More information about the bazaar mailing list