Hi Terry,

>     def led_cycle():
>          traffic_lights()
>          location_lights()
>          sensor_lights()
>
>          print("End of cycle")
>
>     def destroy():
>          GPIO.cleanup()           # Release resource
>
>     if __name__ == '__main__':   # Program start from here
>          try:
>              while True:
>                  led_cycle()
>
>          except KeyboardInterrupt:
>              destroy()
>
> In actual fact only the function traffic_lights() is executed, and once
> that is completed execution starts at the beginning of traffic_lights()
> again.
...
> Any thoughts?

Some alternatives to try to gather more observations.

- Discard the try...except:

    while True:
        led_cycle()

  Ignoring the loss of GPIO.cleanup() for the moment.  Does the
  behaviour now change suggesting exception handling is involved?

- Comment out the call to traffic_lights() in led_cycle().  What
  happens?  Perhaps the same behaviour transfers to location_lights(),
  with sensor_lights() and the print() still not occurring.  Or perhaps
  it now cycles as desired.

- Re-order the three tests instead.  There are six orderings.  Is it
  always traffic_lights() where execution loops early?  Or the first
  one?

    location_lights()    1  1  2  2  3  3
    sensor_lights()      2  3  1  3  1  2
    traffic_lights()     3  2  3  1  2  1

-- 
Cheers, Ralph.

-- 
  Next meeting: Online, Jitsi, Tuesday, 2025-05-06 20:00
  Check to whom you are replying
  Meetings, mailing list, IRC, ...  https://dorset.lug.org.uk
  New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk

Reply via email to