On 3/22/2011 1:02 PM, Jelmer Vernooij wrote:
> On Tue, 2011-03-22 at 09:02 +0000, Martin Pool wrote:
>> On 20 March 2011 09:02, Jelmer Vernooij <email address hidden> wrote:
>>> Great, thanks for confirming.
>>>
>>> This wasn't actually related to windows, but rather to the fact that
>>> some code didn't run when python was used in -O mode. It skipped some
>>> "assert" statements, one of which had a side-effect that was actually
>>> required.
>>
>> Maybe you should stop using (or even ban) assert, like we do in bzr?
>> I don't find that separate debug builds work as well in Python as they
>> sometimes can in C. (Especially because users can turn it on or off
>> without being aware of the consequences.)
> There are a few places where I do actually do fairly expensive things in
> assert statements that I would like to disable for production users. How
> does Bazaar handle that sort of situation?
>
> Cheers,
>
> Jelmer
>
If you had to, you can use:
if __debug__:
That is actually the python magic that assert uses.
That said, the whole point of Martin's comment is that:
a) It generally isn't useful to do stuff in __debug__ and not
elsewhere. Because often you won't realize that a critical section
is in __debug__.
b) Nobody else really does that, so you don't save on anything but
your own code.
c) If you *really* want it, consider using a "-D" style flag.
(debug.debug_flags)
d) Most of that sort of stuff should be covered in a test case, rather
than in production code.
So the expensive 'really validate things are correct', should be
turned into a test case that is run infrequently, rather than
something that slows down production code.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 3/22/2011 1:02 PM, Jelmer Vernooij wrote:
> On Tue, 2011-03-22 at 09:02 +0000, Martin Pool wrote:
>> On 20 March 2011 09:02, Jelmer Vernooij <email address hidden> wrote:
>>> Great, thanks for confirming.
>>>
>>> This wasn't actually related to windows, but rather to the fact that
>>> some code didn't run when python was used in -O mode. It skipped some
>>> "assert" statements, one of which had a side-effect that was actually
>>> required.
>>
>> Maybe you should stop using (or even ban) assert, like we do in bzr?
>> I don't find that separate debug builds work as well in Python as they
>> sometimes can in C. (Especially because users can turn it on or off
>> without being aware of the consequences.)
> There are a few places where I do actually do fairly expensive things in
> assert statements that I would like to disable for production users. How
> does Bazaar handle that sort of situation?
>
> Cheers,
>
> Jelmer
>
If you had to, you can use:
if __debug__:
That is actually the python magic that assert uses.
That said, the whole point of Martin's comment is that:
a) It generally isn't useful to do stuff in __debug__ and not debug_flags)
elsewhere. Because often you won't realize that a critical section
is in __debug__.
b) Nobody else really does that, so you don't save on anything but
your own code.
c) If you *really* want it, consider using a "-D" style flag.
(debug.
d) Most of that sort of stuff should be covered in a test case, rather
than in production code.
So the expensive 'really validate things are correct', should be
turned into a test case that is run infrequently, rather than
something that slows down production code.
John
=:->
-----BEGIN PGP SIGNATURE----- enigmail. mozdev. org/
IqnAACgkQJdeBCY SNAAMKbwCfVxB5C MBm22fs/ TfSSFQ7TTJT 8sFm8aQQ5F28vIi 70
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAk2
CX0AoMhLePjFg3O
=cPoX
-----END PGP SIGNATURE-----