def test_sharedarray_multiprocess(): sa = SharedArray(shape=(10), dtype='int32') np_a = sa.to_numpy() np_a[:] = np.arange(10) # Start remote process, read data from shared array, then return to host # process. proc = mp.Process() sa_mod = proc._import('pyacq.core.stream.sharedarray') sa2 = sa_mod.SharedArray(**sa.to_dict()) np_a2 = sa2.to_numpy(_returnType='value') proc.close() assert np.all(np_a == np_a2)
# -*- coding: utf-8 -*- import initExample ## Add path to library (just for examples; you do not need this) import numpy as np import pyqtgraph.multiprocess as mp import pyqtgraph as pg import time print("\n=================\nStart Process") proc = mp.Process() import os print("parent:", os.getpid(), "child:", proc.proc.pid) print("started") rnp = proc._import('numpy') arr = rnp.array([1, 2, 3, 4]) print(repr(arr)) print(str(arr)) print("return value:", repr(arr.mean(_returnType='value'))) print("return proxy:", repr(arr.mean(_returnType='proxy'))) print("return auto: ", repr(arr.mean(_returnType='auto'))) proc.join() print("process finished") print("\n=================\nStart ForkedProcess") proc = mp.ForkedProcess() rnp = proc._import('numpy') arr = rnp.array([1, 2, 3, 4]) print(repr(arr)) print(str(arr)) print(repr(arr.mean())) proc.join() print("process finished")
start = time.time() print("submit site:", site_dir.name()) print(expt) sub = ExperimentDBSubmission(site_dir, nwb_cache_file) if sub.submitted(): print(" already in DB") else: if '--local' in sys.argv: sub.submit() else: # Do experiment submission in a subprocess to control memory # usage. proc = mp.Process(pyqtapis={'QString': 2, 'QVariant': 2}) try: rdm = proc._import('acq4.util.DataManager') nwb_file = rdm.getFileHandle(expt.nwb_file) nwb_cache_file = rdm.getFileHandle(expt.nwb_cache_file) site_dir = nwb_file.parent() slice_dir = site_dir.parent() rsub = proc._import('submission') sub = rsub.ExperimentDBSubmission( site_dir, nwb_cache_file) fn = sub.submit(_timeout=None) finally: proc.join()