@@ -691,10 +691,13 @@ cdef class RandomState:
691
691
"""
692
692
cdef ndarray state " arrayObject_state"
693
693
state = < ndarray> np.empty(624 , np.uint)
694
- memcpy(< void * > PyArray_DATA(state), < void * > (self .internal_state.key), 624 * sizeof(long ))
694
+ with self .lock:
695
+ memcpy(< void * > PyArray_DATA(state), < void * > (self .internal_state.key), 624 * sizeof(long ))
696
+ has_gauss = self .internal_state.has_gauss
697
+ gauss = self .internal_state.gauss
698
+ pos = self .internal_state.pos
695
699
state = < ndarray> np.asarray(state, np.uint32)
696
- return (' MT19937' , state, self .internal_state.pos,
697
- self .internal_state.has_gauss, self .internal_state.gauss)
700
+ return (' MT19937' , state, pos, has_gauss, gauss)
698
701
699
702
def set_state (self , state ):
700
703
"""
@@ -761,10 +764,11 @@ cdef class RandomState:
761
764
obj = < ndarray> PyArray_ContiguousFromObject(key, NPY_LONG, 1 , 1 )
762
765
if PyArray_DIM(obj, 0 ) != 624 :
763
766
raise ValueError (" state must be 624 longs" )
764
- memcpy(< void * > (self .internal_state.key), < void * > PyArray_DATA(obj), 624 * sizeof(long ))
765
- self .internal_state.pos = pos
766
- self .internal_state.has_gauss = has_gauss
767
- self .internal_state.gauss = cached_gaussian
767
+ with self .lock:
768
+ memcpy(< void * > (self .internal_state.key), < void * > PyArray_DATA(obj), 624 * sizeof(long ))
769
+ self .internal_state.pos = pos
770
+ self .internal_state.has_gauss = has_gauss
771
+ self .internal_state.gauss = cached_gaussian
768
772
769
773
# Pickling support:
770
774
def __getstate__ (self ):
0 commit comments