Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3847

MicroPython • Re: Traffic_Lights.py example error

$
0
0
The button variable hasn't the "global" word in the original example in the book.
No, and it shouldn't need it.

The root problem is that the '_thread' module is, as 'scruss' notes, "experimental". If you import it and use it there is every chance your code will crash and burn, it may not behave as expected, it may throw errors which shouldn't be thrown.

You may get lucky and find something which makes it seem like it's working - as you did by defining 'button' as global - but you may have simply delayed the time it takes to crash and burn. It may look like whatever was done makes it work reliable but you cannot tell if it is or will be.

Unfortunately some believed '_thread' was usable and led people into using it when it isn't, have led them to believe it's more usable than it actually is. That probably happened because the code they produced worked for them at the time, thought it would always work for others. As you have found out; it doesn't.

Statistics: Posted by hippy — Mon Nov 11, 2024 5:18 pm



Viewing all articles
Browse latest Browse all 3847

Trending Articles