Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8130579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:46:02+00:00 2026-06-06T08:46:02+00:00

I have encountered a very weird situation in Python. I have a while True:

  • 0

I have encountered a very weird situation in Python.

I have a while True: loop in a script that constantly grabs real-time data. The data is only meant to be grabbed during business hours, therefore I have a helper function in a module called lib/date.py.

This is the function:

def isTime(utc_now=datetime.datetime.utcnow()): 
    '''
    9:00 AM UTC - 5:00 PM UTC Mon - Fri.

    The parameter utc_now can be used to specify a specific     
    datetime to be checked instead of the utcnow(). 
    '''

    week_day = utc_now.weekday()

    # no good on Saturdays and Sundays
    if 5 == week_day or 6 == week_day:
        return False

    now_int = (utc_now.hour * 60) + utc_now.minute

    if (17 * 60) >= now_int >= (9 * 60):
        return True

    return False

I realize that the way times are checked is an overkill, but this is a simplified version of my function. My real function also includes a bunch of time zone conversions which make the above necessary.

This is my main script (simplified):

def main():
    while True:
        do_ten_seconds()

def do_ten_seconds():
    log.info("alive")

    for i in xrange(10):   
        if isTime():
            log.info("its time")
            # do data grabbing
        sleep(1)

This works perfectly during the week, stopping every week night and continuing the next morning. However, on the weekend, it does not “recover” from the long break. In other words, isTime never returns True Monday morning.

I checked the log, and the script just prints “alive” every 10 seconds, but the data grabbing part never happens (and “its time” is never printed). Hence, I am assuming this means isTime is returning False.

Could it be that because the function is called so frequently over the weekend, and because it returns False so many times in a row, Python caches the results and never recovers from it?

When I spawn the same instance of code while the main script is still running in the faulty mode where isTime is returning False, the new instance gets True from isTime and begins to work perfectly.

What is going on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:46:03+00:00Added an answer on June 6, 2026 at 8:46 am

    Default arguments are calculated at compile time. Make the default value None, and check for that using is None.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have encountered a weird situation while updating/upgrading some legacy code. I have a
I have encountered a very weird behavior while using SimpleDateFormat for parsing a string
I have encountered a situation where it would be very useful to specify a
We have encountered a very strange class not found problem in our web app
I have encountered a most annoying problem that occurs on the PWD variable when
I have encountered a problem in my application. I have two forms, one that
I have encountered the strange problem, that linux c++ compiler includes the files from
I encountered some very weird behaviour which I think is a bug, but I
I'm trying to learn python and have encountered some strange behaviour. I am experimenting
I have encountered a very strange issue. Whenever I use the .NET membership provider

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.