Joulescope Memory Issues

Driving the Joulescope with a Raspberry Pi 4 Model B.

From Python, I am using it pretty simply

    joulescope_device = scan_require_one(config='auto')
    with joulescope_device:
        data = joulescope_device.read(contiguous_duration=duration)

    current, voltage = np.mean(data, axis=0, dtype=np.float64)

I call this with duration set to 0.1. After running this several times in a row, with maybe a half second between iterations, I begin to get the following:

not enough memory: reducing duration from 30 to 29

Followed by:

not enough memory: reducing duration from 30 to 3

Until finally, I am thrown an error:

  File "/home/pi/ICT/venv/lib/python3.9/site-packages/joulescope/driver.py", line 1309, in __enter__
    self.open()
  File "/home/pi/ICT/venv/lib/python3.9/site-packages/joulescope/driver.py", line 551, in open
    self._stream_buffer_open()
  File "/home/pi/ICT/venv/lib/python3.9/site-packages/joulescope/driver.py", line 526, in _stream_buffer_open
    self.stream_buffer = StreamBuffer(stream_buffer_duration, reductions,
  File "joulescope\stream_buffer.pyx", line 482, in joulescope.stream_buffer.StreamBuffer.__cinit__
ValueError: length to small

It is rare to get this to repeat exactly, but the Joulescope is almost always reducing the measurement duration.

Any thoughts or recommendations on how to take fairly frequency small measurements?

Hi @hownowbrowncow . Is this all that is in python and you are calling this script from the command line?

I am going to presume that this is a code snippet that you are calling within a larger python script. Without seeing the rest of your code, I can’t be certain, but it sounds like the code contains a python memory leak. I am guessing the code creates multiple joulescope_device instances without them going out of scope and being garbage collected.

It will be easier and faster to reuse the same instance, like this:

joulescope_device = scan_require_one(config='auto')
with joulescope_device:
    while keep_going():
        # wait for some condition
        data = joulescope_device.read(contiguous_duration=duration)
        current, voltage = np.mean(data, axis=0, dtype=np.float64)
        # save test data

Does this work for your code?

Hi @hownowbrowncow - Did this work for you? Are you up and running? I am going to mark the above as the solution. However, please reply if you are still seeing problems.

@mliberty this did work for me, thank you! I’ve created a function with a previously scanned joulescope device as follows.

def joulescope_capture(joulescope_device, duration):

    results_dict = {}

    # joulescope_device = scan_require_one(config='auto')
    with joulescope_device:
        data = joulescope_device.read(contiguous_duration=duration)

    current, voltage = np.mean(data, axis=0, dtype=np.float64)

    del data
    gc.collect()

    results_dict['voltage'] = voltage
    results_dict['current'] = current

    return results_dict

I needed to delete and garbage collect the data to mitigate memory issues. The test has been behaving now.

Thank you for your help!

1 Like