Movement related to temperature

The delay function is throwing in an error every now and then so I tried the millis() function but I am having a small problem.
When I use int period = 10000; up to 30000 it works but when I try and go 40000 or above it stops working. Even in this sample code it stops after 30000
What am I doing wrong or missing?

int period = 40000;
unsigned long time_now = 0;
 
void setup() {
    Serial.begin(115200);
}
 
void loop() {
    time_now = millis();
   
    Serial.println("Hello");
   
    while(millis() < time_now + period){
        //wait approx. [period] ms
    }
}