I run my program:

from gpiozero import PWMLED

ledpins = [2, 3, 4]
z = 10

for i in ledpins:
    PWMLED(i).blink(on_time=1/z, off_time=1/z, n=3)

I tried it and got:

Exception Exception RuntimeErrorException RuntimeError: RuntimeError: RuntimeError('cannot join current thread',): RuntimeError('cannot join current thread',) in RuntimeError('cannot join current thread',) in <bound method PWMLED.__del__ of <gpiozero.PWMLED object on pin GPIO2, active_high=True, is_active=False>> in <bound method PWMLED.__del__ of <gpiozero.PWMLED object on pin GPIO3, active_high=True, is_active=False>> ignored
<bound method PWMLED.__del__ of <gpiozero.PWMLED object on pin GPIO4, active_high=True, is_active=False>> ignored



Two issues: you are not assigning the objects at anything, and your script is reaching the end of the file and exiting.

While PWMLED(i).blink() is valid Python, you are not keeping the objects alive, and they are being cleaned up by the garbage collector. You need to assign the devices to an object name, for example:

led = PWMLED(2)

You also need to keep the script running after you've set up your blink, as it goes into the background immediately. We tend to suggest using signal.pause from the standard library:

from gpiozero import PWMLED
from signal import pause

led = PWMLED(2)



Also, I would recommend using LEDBoard:

from gpiozero import LEDBoard
from signal import pause

leds = LEDBoard(2, 3, 4, pwm=True)

leds.blink(1/10, 1/10, n=30)


I guess the problem is you instantiate the object and immediately try to configure the object. Perhaps there is a race condition. It might be worthwhile to raise a gpiozero issue to find the root problem.


As a work around try the following.

import time

from gpiozero import PWMLED

ledpins = [2, 3, 4]

z = 10.0

for i in ledpins:

for i in obj:
   i.blink(on_time=1/z, off_time=1/z, n=30)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.