Not sure if my problem is related to RaspberryPi, GPIO or just my understanding of Python but since I'm detecting my problem while playing with a button attached to my PI I ask it here.

I have a simple setup which just connects a button to port 26.
When the button is pressed I set canExit to True in the hope the main while loop will stop. This does not happen.
Can somebody explain me why ? 

```
import time
import sys
import RPi.GPIO as GPIO
from gpiozero import Button

BUTTON_PIN=26
button = Button(BUTTON_PIN)

canExit=False

def onButtonPress():
    print("button pressed")
    canExit=True
    print("end of logic")

def cleanup(): #(signal, frame): 
    GPIO.setmode(GPIO.BCM)
    GPIO.cleanup()
    print("end of program")
    sys.exit(0)

button.when_pressed=onButtonPress
print("Please press a button")
while not(canExit):
    print("*",end="")
    time.sleep(0.1)
print("Nearly there, just cleaning up")
cleanup()

```

My output:

```
Please press a button
**************************button pressed
end of logic
*********************************************************************

```

But my program doesn't stop. The "Nearly there" is never printed and the cleanup() is not executed. The while loop keeps running