Skip to content

Commit

Permalink
BUG: Fix SharedMemory references on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kernc committed Feb 18, 2025
1 parent 58658b4 commit d1d4979
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backtesting/backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,12 +1508,15 @@ def _batch(seq):
with mp.Pool() as pool, \
SharedMemoryManager() as smm:

shm_refs = [] # https://stackoverflow.com/questions/74193377/filenotfounderror-when-passing-a-shared-memory-to-a-new-process#comment130999060_74194875 # noqa: E501

def arr2shm(vals):
nonlocal smm
shm = smm.SharedMemory(size=vals.nbytes)
buf = np.ndarray(vals.shape, dtype=vals.dtype, buffer=shm.buf)
buf[:] = vals[:] # Copy into shared memory
assert vals.ndim == 1, (vals.ndim, vals.shape, vals)
shm_refs.append(shm)
return shm.name, vals.shape, vals.dtype

data_shm = tuple((
Expand Down

0 comments on commit d1d4979

Please sign in to comment.