Comment on PEP-0238

Robin Becker robin at jessikat.fsnet.co.uk
Thu Jul 12 06:00:56 EDT 2001


In article <9iirju$j9rjr$1 at ID-11957.news.dfncis.de>, Emile van Sebille
<emile at fenx.com> writes
>
>I've written a module that takes a few steps in the direction I'd like to
>see things go, but even if that's not in the cards I'll probably use it
>anyway.  It works like Tim's FixedPoint, but uses precision in a slightly
>different way.  When run as __main__, it imports FixedPoint to compare
>results as it tests.  Overall, this feels more like what I had in mind.
>
>Anyway, a sample session follows.  If anyone is interested in testing/using
>this, e-mail me and I'll send you back a copy.
>
>
>Emile van Sebille
>emile at fenx.com
>

how do these global class attributes work with threads? a lot of people
are asking me about Zope (vis a vis reportlab) I keep telling them that
reportlab isn't thread safe. I had imagined just packaging up all the
module globals in some way and making things thread safe with a few
locks.  Now I see that BNum.PRECISION is affecting all instances of the
class, perhaps including someone else's thread so can BNum and similar
be used in a real multithreaded environment like Zope?


>>>> import BNum
>>>> bn = Bnum.Bnum
>>>> a = bn(1.111)
>>>> a
>1.11
>>>> BNum.PRECISION = 6
>>>> a = bn(1.111)
>>>> a
>1.111000
>>>> a * a * a * a
>1.523548
>>>> b = 1.111
>>>> b ** 4
>1.5235483310410001
>>>> BNum.PRECISION = 12
>>>> a * a * a * a
>1.523548331041
>>>> BNum.PRECISION = 18
>>>> a * a * a * a
>1.523548331041000000
>>>>
>>>> a / 1.234
>0.900324149108589951
>>>> a -.346
>0.765000000000000000
>>>> a
>1.111000000000000000
>>>> a - 1.23456
>-0.123560000000000000
>>>> a - 1.234567890
>-0.123567890000000000
>>>> a - 1.234567890123456789
>-0.123567890120000000
>>>> a - '1.234567890123456789'
>TypeError: object can't be converted to long
>>>> a - bn('1.234567890123456789')
>-0.123567890123456789
>
>

-- 
Robin Becker



More information about the Python-list mailing list