[Numpy-discussion] numpy.random.RandomState threadsafe?

Hoyt Koepke hoytak at gmail.com
Tue Mar 11 18:08:35 EDT 2008


Okay, thanks!  I won't be using the multivariate_normal function in my
code, so this should work fine.

--Hoyt

On Tue, Mar 11, 2008 at 3:00 PM, Robert Kern <robert.kern at gmail.com> wrote:
>
> On Tue, Mar 11, 2008 at 4:18 PM, Hoyt Koepke <hoytak at gmail.com> wrote:
>  > This should be a really quick question.  Is a RandomState object
>  >  thread safe?  I'm wanting to use a common RandomState object in a
>  >  multithreaded program, and I need to know if it's necessary to protect
>  >  it with a lock (which wouldn't be difficult).
>
>  For nearly all of the methods, yes, they should be. RandomState is
>  implemented in C (using Pyrex) and the GIL is acquired before calling
>  any C functions. The caveat here is that the methods
>  multivariate_normal() calls back out to Python-implemented functions.
>  It is possible that the GIL gets released during that call and that
>  another thread can pick up execution then. However, even this should
>  not be a problem as far as safety goes; no internal state is read or
>  changed after the external call.
>
>  --
>  Robert Kern
>
>  "I have come to believe that the whole world is an enigma, a harmless
>  enigma that is made terrible by our own mad attempt to interpret it as
>  though it had an underlying truth."
>   -- Umberto Eco
>  _______________________________________________
>  Numpy-discussion mailing list
>  Numpy-discussion at scipy.org
>  http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list