# Python API bug: "Moku 502 Error" when relinquish\_ownership()

**URL:** <https://forum.liquidinstruments.com/t/python-api-bug-moku-502-error-when-relinquish-ownership/856>\
**Category:** Support & Troubleshooting\
**Created:** [December 1, 2023, 5:32am UTC](https://forum.liquidinstruments.com/t/python-api-bug-moku-502-error-when-relinquish-ownership/856 "2023-12-01T05:32:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nnosk55](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/nnosk55/32/249_2.png) [@nnosk55](https://forum.liquidinstruments.com/u/nnosk55)\
**Post date:** [December 1, 2023, 5:32am UTC](https://forum.liquidinstruments.com/t/python-api-bug-moku-502-error-when-relinquish-ownership/856/1 "2023-12-01T05:32:52Z")

</div>

Moku model: Moku Pro, Firmware 587  
Operating system: Mac OS Ventura 13.4.1  
Software version: Moku 3.1.0, Mokucli 2.2.1

The following combination of settings causes a 502 error when trying to relinquish\_ownership() of the Moku Pro in Mim mode. There doesn’t appear to be any issues with function, until I try to relinquish ownership, but I cant be certain.

If I remove any single one of those lines, it seems to work okay… Others who’ve posted about similar issues on the forum seems to suggest that its about having a double up of instruments, but that doesnt appear to be the case here.

```auto
from moku.instruments import CloudCompile, MultiInstrument, ArbitraryWaveformGenerator, WaveformGenerator, LockInAmp

mim = MultiInstrument('10.250.2.116', force_connect=True, platform_id=4)
arb = mim.set_instrument(1, ArbitraryWaveformGenerator)
#mcc = mim.set_instrument(2, CloudCompile, bitstream="multip_mokupro_587_e5cacd7.tar.gz") # N.B. Not nessecary to replicate the bug so I commented it out
wg = mim.set_instrument(3, WaveformGenerator)
lia = mim.set_instrument(4, LockInAmp)

wg.generate_waveform(channel=1,type='Sine', amplitude = 1.0,frequency = 144e6,phase = 0)

lia.set_demodulation(mode="Internal",frequency=144e6)

arb.burst_modulate(1, "InputA", "NCycle", burst_cycles=1e6, trigger_level=0.8)

mim.relinquish_ownership()

```

---

<div class="post-metadata">

**Author:** ![nadia](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/nadia/32/315_2.png) [@nadia](https://forum.liquidinstruments.com/u/nadia)\
**Post date:** [December 4, 2023, 2:53am UTC](https://forum.liquidinstruments.com/t/python-api-bug-moku-502-error-when-relinquish-ownership/856/2 "2023-12-04T02:53:34Z")

</div>

Thank you for bringing this to our attention! We’ve noted this as a new bug in Multi-Instrument mode for the Moku:Pro and are working towards a fix. For now, the best solution for when this occurs would be to comment out `mim.relinquish_ownership` and rely on `force_connect=True` when connecting to your Moku:Pro.

---

<div class="post-metadata">

**Author:** ![nnosk55](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/nnosk55/32/249_2.png) [@nnosk55](https://forum.liquidinstruments.com/u/nnosk55)\
**Post date:** [December 5, 2023, 1:59am UTC](https://forum.liquidinstruments.com/t/python-api-bug-moku-502-error-when-relinquish-ownership/856/3 "2023-12-05T01:59:26Z")

</div>

Thank you! Just to add to this, when I comment out relinquish\_ownership(), the Moku gives another 502 error when trying to re-run the script and connect to the device. I have to run the script twice to get it to connect.

Its not an issue for me to keep developing my application, but I thought I should mention it 🙂

---

<div class="post-metadata">

**Author:** ![nadia](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.liquidinstruments.com/nadia/32/315_2.png) [@nadia](https://forum.liquidinstruments.com/u/nadia)\
**Post date:** [December 5, 2023, 4:03am UTC](https://forum.liquidinstruments.com/t/python-api-bug-moku-502-error-when-relinquish-ownership/856/4 "2023-12-05T04:03:41Z")

</div>

Ah yes, I did notice that! If it does become an issue and you don’t mind a little extra run time, you could try something like this for more reliable runs:

```auto
import time
######### YOUR CODE #########
try:
	mim.relinquish_ownership()
except:
	time.sleep(2)
	mim.relinquish_ownership()

```
