# Scripting from the interactive console

**URL:** <https://forum.opencyphal.org/t/scripting-from-the-interactive-console/527>\
**Category:** PyCyphal\
**Created:** [June 12, 2019, 9:20pm UTC](https://forum.opencyphal.org/t/scripting-from-the-interactive-console/527 "2019-06-12T21:20:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phantom329](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/p/838e76/32.png) [@Phantom329](https://forum.opencyphal.org/u/Phantom329)\
**Post date:** [June 12, 2019, 9:20pm UTC](https://forum.opencyphal.org/t/scripting-from-the-interactive-console/527/1 "2019-06-12T21:20:08Z")

</div>

I am trying to run a periodic stress test by cycling an ESC on and off every 20 min. I also need throttle (ideally current control) and I wrote a script. I am not great at coding and I can’t figure out why the entire gui tool crashes. Also I don’t know how to run a certain number of times without using a blocking call.

```auto
# length of test and time between tests in minutes
length = 20
wait = 20
no_runs = 10
throttle = 64

def run_once():
	print('Starting run')
        # warning beep
	broadcast(uavcan.equipment.indication.BeepCommand(frequency=500, duration=0.1), interval=0.5, duration=1)
	node.defer(5, spin)

def spin():
	node.spin(length*60)

def run_test():
	print('Starting test')
	message = uavcan.equipment.esc.RawCommand(cmd=[int(82*throttle), 0, 0, 0])
	node.broadcast(message)
	run_once()
	periodic((length+wait)*60, run_once)

```

It crashes when it tries to run node.spin. Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [June 15, 2019, 8:41pm UTC](https://forum.opencyphal.org/t/scripting-from-the-interactive-console/527/2 "2019-06-15T20:41:59Z")

</div>

`node.spin` is run by the GUI tool itself, you must not call it from your script. You can implement your functions in a non-blocking way as in any IoC framework; you can find a useful example here: [https://uavcan.org/GUI\_Tool/User\_guide/#programming-tips](https://uavcan.org/GUI_Tool/User_guide/#programming-tips)
