[IronPython] Problem with random module in IPY 1.1.1
curt at hagenlocher.org
Tue Oct 14 01:12:53 CEST 2008
The underlying problem in the Python code is likely to be because of the
behavior of the "random" function in the C library. And for us, this is
actually a problem in the BCL. Someone just posted the exact same behavior
to an internal mailing list, but from a C# program. They wrote: "I just
encountered this behavior of Random.Next(): if I create one Random object
and call Next() from one thread (doesn't need to be the main thread),
everything works fine. However, if I create one Random object and call
Next() on it from two or more threads, after a while it will start to return
0 all the time, and its internal SeedArray becomes all 0."
The Python library contains a comment which reads "The random() method is
implemented in C, executes in a single Python step, and is, therefore,
threadsafe" so arguably, this is a bug in the _random module of IronPython.
Please report it to CodePlex.
On Mon, Oct 13, 2008 at 1:57 PM, Ronnie Maor <ronnie.maor at gmail.com> wrote:
> problem was caused by calling random from several threads without locking.
> it reproduces more easily in IPy than in CPython because of the GIL, but
> it's documented as not thread safe for CPython too.
> On Sun, Oct 12, 2008 at 11:27 AM, Asaf Kleinbort <asaf at itstructures.com>wrote:
>> We have encountered two strange errors in the 'random' module:
>> 1. At some point the random method 'getrandbits(63)' started (and
>> kept) returning 0 – until we restarted the application.
>> 2. The random method 'shuffle' when applied on a list kept
>> returning the same ordered list. Again – restarting the application solved
>> the problem
>> An interesting remark is that issue #1 happened to us today in two
>> different applications, around the same time.
>> Any ideas?
>> Users mailing list
>> Users at lists.ironpython.com
> Users mailing list
> Users at lists.ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironpython-users