FilipDominec / rp2daq

Raspberry Pi Pico firmware for universal hardware control & measurement, along with a user-friendly Python frontend
MIT License
27 stars 4 forks source link

Multiprocessing error on Windows 11: ctypes objects containing pointers cannot be pickled #5

Closed FilipDominec closed 1 year ago

FilipDominec commented 1 year ago

The commit 4ee6530 (from Jun 9 2023) introduced multiprocessing; it works flawlessly on Linux, but on Windows 11 this throwed

C:\Users\ts\rp2daq-main> python .\hello_world.py
2023-08-29 13:48:14,459 (MainThread) connected to rp2daq device with manufacturer ID = E66118604B826B2A
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1520.0_x64__qbz5n2kfra8p0\Lib\multiprocessing\spawn.py", line 113, in spawn_main
    new_handle = reduction.duplicate(pipe_handle,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1520.0_x64__qbz5n2kfra8p0\Lib\multiprocessing\reduction.py", line 79, in duplicate
    return _winapi.DuplicateHandle(
           ^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 50] The request is not supported

This is critical, as it disables rp2daq use from Windows.

epsi1on commented 1 year ago

I had same issue in windows.

FilipDominec commented 1 year ago

After much testing, this should be finally fixed in 4019c3e by using a separate communication process, two multiprocess.Queue objects for the incoming and outgoing chunks of bytes, and launching two threads in the process to service their respective queues.

With some optimisations, the full speed reception of the ADC data stream (i.e. 500 kSps ~ 750 kB/s) seems to work reliably and continuously, even if the user script is 100% busy. (See example_ADC_async.py)