Steps to reproduce:
From 6f1f6b3 with a minor revision:
diff --git a/lab_10_template.py b/lab_10_template.py
index 53623b1..acbd525 100644
--- a/lab_10_template.py
+++ b/lab_10_template.py
@@ -188,7 +188,7 @@ if __name__ == "__main__":
try:
ads.use_wavegen(channel=1, function=wavegen_functions["sine"], offset_v=0, freq_hz=1e3, amp_v=1)
### FILL IN THIS LINE FOR L10.2(a)
- raw_data = ...
+ # raw_data = ...
ads.close_wavegen()
### UNCOMMENT THIS CODE FOR L10.3(a)
-
Run: python lab_10_template.py (runs as expected)
-
Re-run: python lab_10_template.py
Output:
[1] 98546 segmentation fault python lab_10_template.py
The proximate cause is not properly tearing down handles when the __main__ block finishes running (.close_scope(), .disconnect(), etc are only called in the Exception handler).
I believe the root cause is the Waveforms SDK storing a ctype.byref memory address pointer in a Python global variable. I haven't traced the dwf.framework calls to verify, but passing around a memory address this way creates a lot of opportunities to segfault.
https://github.com/Digilent/WaveForms-SDK-Getting-Started-PY/blob/master/WF_SDK/device.py#L204
https://github.com/Digilent/WaveForms-SDK-Getting-Started-PY/blob/master/WF_SDK/device.py#L278
The device enumerator example included in the SDK works fine, so I'm ruling out any connectivity issues:
$ python ../waveforms-sdk-digilent.waveforms_v3.24.2/samples/py/Device_Enumeration.py
DWF Version: b'3.24.2'
Number of Devices: 1
------------------------------
Device 0 :
Name: Analog Discovery Studio SN:210384B012EE
ID: 3 rev: C 0x403
Configurations:
0. AnalogIn: 2 x 8192 AnalogOut: 2 x 4096 DigitalIn: 16 x 4096 DigitalOut: 16 x 1024
1. AnalogIn: 2 x 16384 AnalogOut: 2 x 1024 DigitalIn: 16 x 1024 DigitalOut: 0 x 0
2. AnalogIn: 2 x 2048 AnalogOut: 2 x 16384 DigitalIn: 0 x 0 DigitalOut: 0 x 0
3. AnalogIn: 2 x 512 AnalogOut: 2 x 256 DigitalIn: 16 x 16384 DigitalOut: 16 x 16384
4. AnalogIn: 2 x 8192 AnalogOut: 2 x 4096 DigitalIn: 16 x 4096 DigitalOut: 16 x 1024 1V8_Digital_Input
5. AnalogIn: 2 x 8192 AnalogOut: 4 x 4096 DigitalIn: 16 x 2048 DigitalOut: 8 x 256 Power_Supply_Waveform_Generator
6. AnalogIn: 2 x 512 AnalogOut: 2 x 256 DigitalIn: 16 x 16384 DigitalOut: 16 x 16384 1V8_Digital_Input
7. AnalogIn: 2 x 8192 AnalogOut: 2 x 1024 DigitalIn: 16 x 16384 DigitalOut: 8 x 256
Additional env/version info:
$ which python
/Users/leigh/Library/Caches/pypoetry/virtualenvs/phys111a-lab10-SYt7gGMh-py3.11/bin/python
$ python --version
Python 3.11.12
$ pip freeze | grep WF_SDK
WF_SDK @ git+https://github.com/Digilent/WaveForms-SDK-Getting-Started-PY@3e5fcd1b10a6a8c83bf1e5356d6ac61f15327d52
Steps to reproduce:
From 6f1f6b3 with a minor revision:
Run:
python lab_10_template.py(runs as expected)Re-run:
python lab_10_template.pyOutput:
The proximate cause is not properly tearing down handles when the
__main__block finishes running (.close_scope(), .disconnect(), etc are only called in the Exception handler).I believe the root cause is the Waveforms SDK storing a
ctype.byrefmemory address pointer in a Pythonglobalvariable. I haven't traced thedwf.frameworkcalls to verify, but passing around a memory address this way creates a lot of opportunities to segfault.https://github.com/Digilent/WaveForms-SDK-Getting-Started-PY/blob/master/WF_SDK/device.py#L204
https://github.com/Digilent/WaveForms-SDK-Getting-Started-PY/blob/master/WF_SDK/device.py#L278
The device enumerator example included in the SDK works fine, so I'm ruling out any connectivity issues:
Additional env/version info: