@@ -685,10 +685,13 @@ cdef class RandomState:
685
685
"""
686
686
cdef ndarray state " arrayObject_state"
687
687
state = < ndarray> np.empty(624 , np.uint)
688
- memcpy(< void * > PyArray_DATA(state), < void * > (self .internal_state.key), 624 * sizeof(long ))
688
+ with self .lock:
689
+ memcpy(< void * > PyArray_DATA(state), < void * > (self .internal_state.key), 624 * sizeof(long ))
690
+ has_gauss = self .internal_state.has_gauss
691
+ gauss = self .internal_state.gauss
692
+ pos = self .internal_state.pos
689
693
state = < ndarray> np.asarray(state, np.uint32)
690
- return (' MT19937' , state, self .internal_state.pos,
691
- self .internal_state.has_gauss, self .internal_state.gauss)
694
+ return (' MT19937' , state, pos, has_gauss, gauss)
692
695
693
696
def set_state (self , state ):
694
697
"""
@@ -755,10 +758,11 @@ cdef class RandomState:
755
758
obj = < ndarray> PyArray_ContiguousFromObject(key, NPY_LONG, 1 , 1 )
756
759
if PyArray_DIM(obj, 0 ) != 624 :
757
760
raise ValueError (" state must be 624 longs" )
758
- memcpy(< void * > (self .internal_state.key), < void * > PyArray_DATA(obj), 624 * sizeof(long ))
759
- self .internal_state.pos = pos
760
- self .internal_state.has_gauss = has_gauss
761
- self .internal_state.gauss = cached_gaussian
761
+ with self .lock:
762
+ memcpy(< void * > (self .internal_state.key), < void * > PyArray_DATA(obj), 624 * sizeof(long ))
763
+ self .internal_state.pos = pos
764
+ self .internal_state.has_gauss = has_gauss
765
+ self .internal_state.gauss = cached_gaussian
762
766
763
767
# Pickling support:
764
768
def __getstate__ (self ):
0 commit comments