# Closing program

**URL:** <https://forum.sunfounder.com/t/closing-program/4311>\
**Category:** Robotic kit for Raspberry Pi\
**Created:** [January 27, 2026, 10:54am UTC](https://forum.sunfounder.com/t/closing-program/4311 "2026-01-27T10:54:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![luigi\_fe](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@luigi\_fe](https://forum.sunfounder.com/u/luigi_fe)\
**Post date:** [January 27, 2026, 10:54am UTC](https://forum.sunfounder.com/t/closing-program/4311/1 "2026-01-27T10:54:09Z")

</div>

If I close a program as examples of PiDog [eg: Pidog.close()] I have PiDog blocked and I cannot run another script.

I must turn off my Dog and then I can start again.

Some suggestion? Thank you!

---

<div class="post-metadata">

**Author:** ![jhthurber](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jhthurber](https://forum.sunfounder.com/u/jhthurber)\
**Post date:** [January 27, 2026, 12:09pm UTC](https://forum.sunfounder.com/t/closing-program/4311/2 "2026-01-27T12:09:38Z")

</div>

I had the same problem with some of the provided examples. I believe the gpio pins are not being released properly. GPIO.cleanup() should be run at the end of the script.

---

<div class="post-metadata">

**Author:** ![Spf650](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@Spf650](https://forum.sunfounder.com/u/Spf650)\
**Post date:** [January 27, 2026, 1:55pm UTC](https://forum.sunfounder.com/t/closing-program/4311/3 "2026-01-27T13:55:53Z")

</div>

I tried to explain this to my best understanding here, and gave 3 alternatives. Hopefully its clear!

> [@GPIO state after a program abort or user exit](https://forum.sunfounder.com/t/gpio-state-after-a-program-abort-or-user-exit/4181):
>
> I hope this little topic is of some help I’ve seen several user questions whereby when a program terminates incorrectly for whatever reason, it can leave the GPIO in a “busy” state. Usually requiring a reboot. Instead of a reboot one can often find the owner process id and just kill it e.g running some python code such as DummySpeech.py may show … File “/usr/lib/python3/dist-packages/lgpio.py”, line 458, in \_u2i raise error(error\_text(v)) lgpio.error: ‘GPIO busy’ on subsequent runs. To …

As far as I could ever determine, dog.close() is not a cleanup method, it is a terminal control-flow primitive, it assumes it is called from top-level (parent) code and it was never meant to return.

---

<div class="post-metadata">

**Author:** ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)\
**Post date:** [January 28, 2026, 6:25am UTC](https://forum.sunfounder.com/t/closing-program/4311/5 "2026-01-28T06:25:29Z")

</div>

Some users encountered the same issue and resolved it by reinstalling the system, then following the tutorial steps to install all code again.

An important prerequisite is not to run the command  
sudo apt install git python3-pip python3-setuptools python3-smbus,  
as this instruction is specifically intended for the Lite system and is not needed for the desktop operating system.

You may try the following to see if it resolves the issue:

Please proceed to install the source code by following the steps in our online tutorial:  
[https://docs.sunfounder.com/projects/pidog/en/latest/python/python\_start/install\_all\_modules.html#install-all-the-modules-important](https://docs.sunfounder.com/projects/pidog/en/latest/python/python_start/install_all_modules.html#install-all-the-modules-important)

Remember not to execute the following command:  
sudo apt install git python3-pip python3-setuptools python3-smbus

Instead, directly install the robot-hat, vilib, and pidog library code.

If any errors occur during installation, please provide us with the complete error messages so we can help analyze and resolve the issue.

Once all library codes are successfully installed, try running the example scripts again to see how it works.

---

<div class="post-metadata">

**Author:** ![luigi\_fe](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@luigi\_fe](https://forum.sunfounder.com/u/luigi_fe)\
**Post date:** [January 28, 2026, 7:51am UTC](https://forum.sunfounder.com/t/closing-program/4311/6 "2026-01-28T07:51:06Z")

</div>

Thank you. I’ll try and I tell you.  
Best regards.  
Luigi

---

<div class="post-metadata">

**Author:** ![luigi\_fe](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@luigi\_fe](https://forum.sunfounder.com/u/luigi_fe)\
**Post date:** [January 28, 2026, 1:50pm UTC](https://forum.sunfounder.com/t/closing-program/4311/8 "2026-01-28T13:50:09Z")

</div>

Good afternoon.  
I have tried, but per issue remains.  
I attach the program, copied from your page, and the error that I find when I execute the program for the second time.  
I must turn off Pidog and then it works, for once!  
Thanks for your suggestions.  
Best regards.  
Luigi Federici

(Attachment programma.pdf is missing)

(Attachment Errore.pdf is missing)

---

<div class="post-metadata">

**Author:** ![luigi\_fe](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@luigi\_fe](https://forum.sunfounder.com/u/luigi_fe)\
**Post date:** [January 28, 2026, 2:01pm UTC](https://forum.sunfounder.com/t/closing-program/4311/9 "2026-01-28T14:01:11Z")

</div>

Good afternoon.  
I have tried, but per issue remains.  
I attach the program, copied from your page, and the error that I find when I execute the program for the second time.  
I must turn off Pidog and then it works, for once!  
Thanks for your suggestions.  
Best regards.  
Luigi Federici

P.S. I cannot attach my pdf or jpg file, so I copy them:

**Program:**

# !/usr/bin/env python3

‘’’ play sound effecfs

Note that you need to run with “sudo”

API:

Pidog.speak(name, volume=100)

play sound effecf in the file “../sounds”

- name str, file name of sound effect, no suffix required, eg: “angry”

- volume int, volume 0-100, default 100

‘’’

from pidog import Pidog

import os

import time

# cambia la directory di lavoro

abspath = os.path.abspath(os.path.dirname( **file** ))

os.chdir(abspath)

my\_dog = Pidog()

print(“\033[033mNote that you need to run with "sudo", otherwise there may be no sound.\033[m”)

# my\_dog.speak(“angry”)

# time.sleep(2)

for name in os.listdir(‘../sounds’):

name = name.split(‘.’)[0] # rimuovi il suffisso

print(name)

my\_dog.speak(name)

# my\_dog.speak(name, volume=50)

time.sleep(3) # Nota: la durata di ogni effetto sonoro è diversa

print(“closing …”)

my\_dog.close()

**Error:**

Traceback (most recent call last):

File “/usr/lib/python3/dist-packages/gpiozero/pins/pi.py”, line 411, in pin

pin = self.pins\*\*[info]\*\*

```auto

**KeyError** : PinInfo(number=29, name='GPIO5', names=frozenset({'J8:29', 'GPIO5', 'BOARD29', 'BCM5', 'WPI21', '5', 5}), pull='', row=15, col=1, interfaces=frozenset({'', 'gpio', 'dpi', 'uart', 'i2c', 'spi'}))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/luigi_fe/prog/prova_9.py", line 10, in <module>

my_dog = Pidog()

File "/usr/local/lib/python3.13/dist-packages/pidog/pidog.py", line 131, in __init__

utils.reset_mcu**()**

~~~~~~~~~~~~~~~ **^^**

File "/usr/local/lib/python3.13/dist-packages/robot_hat/utils.py", line 155, in reset_mcu

pin = Pin("MCURST")

File "/usr/local/lib/python3.13/dist-packages/robot_hat/pin.py", line 96, in __init__

self.setup**(mode, pull, active_state)**

~~~~~~~~~~ **^^^^^^^^^^^^^^^^^^^^^^^^^^**

File "/usr/local/lib/python3.13/dist-packages/robot_hat/pin.py", line 134, in setup

self.gpio = OutputDevice**(self._pin_num)**

~~~~~~~~~~~~ **^^^^^^^^^^^^^^^**

File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 108, in __call__

self = super(). __call__ (*args, **kwargs)

File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", line 74, in __init__

super(). __init__ **(pin, pin_factory=pin_factory)**

~~~~~~~~~~~~~~~~ **^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^**

File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 75, in __init__

super(). __init____ (*args, **kwargs)__

~~~~~~~~~~~~~~~~ **^^^^^^^^^^^^^^^^^**

File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 553, in __init__

pin = self.pin_factory.pin(pin)

File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 413, in pin

pin = self.pin_class(self, info)

File "/usr/lib/python3/dist-packages/gpiozero/pins/lgpio.py", line 126, in __init__

lgpio.gpio_claim_input**(**

~~~~~~~~~~~~~~~~~~~~~~ **^**

**self.factory._handle, self._number, lgpio.SET_PULL_NONE)**

**^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^**

File "/usr/lib/python3/dist-packages/lgpio.py", line 755, in gpio_claim_input

return _u2i(_lgpio._gpio_claim_input(handle&0xffff, lFlags, gpio))

File "/usr/lib/python3/dist-packages/lgpio.py", line 458, in _u2i

raise error(error_text(v))

**lgpio.error** : 'GPIO busy'
```

---

<div class="post-metadata">

**Author:** ![SunFounder\_Moderator](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@SunFounder\_Moderator](https://forum.sunfounder.com/u/SunFounder_Moderator)\
**Post date:** [January 29, 2026, 6:48am UTC](https://forum.sunfounder.com/t/closing-program/4311/10 "2026-01-29T06:48:42Z")

</div>

Please contact our official email at [service@sunfounder.com](mailto:service@sunfounder.com) and provide us with the code you are running along with the complete error message. This will help us analyze and resolve the issue for you.

Please note: Do not run two or more code scripts simultaneously, as this will cause GPIO pin conflicts.

The code you are running is your own, correct?  
When you run our project code script, can you stop it normally by pressing Ctrl+C, without having to execute the script a second or multiple times?

If you are running your own code, we suspect there may be an issue with the code itself.
