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

  • Home
  • SEARCH
  • 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 9170125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:58:25+00:00 2026-06-17T15:58:25+00:00

Seems like there should be a simple solution using the time module or something,

  • 0

Seems like there should be a simple solution using the time module or something, but I’ve tried a few things and nothing seems to work. I need something like this to work:

hungry = True
if line.find ('feeds'):
    #hungry = False for 60 seconds, then hungry is true again

Anyone have a solution for this?

edit: As for what I’ve tried, I’ve tried this bit of code:

if hungry==True:
     print('yum! not hungry for 20 seconds')
     hungry = False
     i = 20
     while(i>0):
         i-=1
         time.sleep(1)
         if(i==0):
             hungry = True

But that doesn’t work because the program just pauses until hungry is True again, and hungry being false while the program sleeps won’t help; it should be false for a certain amount of time while the rest of the program works

edit: It looks like this won’t be possible without threading. I’ll have to either find a new solution, or learn to use threading. Thanks for all the help anyways, I seriously appreciate it!

  • 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-17T15:58:26+00:00Added an answer on June 17, 2026 at 3:58 pm

    You could encapsulate the behaviour you want in a TimedValue class, but that might be overkill here– I’d probably just do something like

    now = time.time()
    hunger = lambda: time.time() > now + 60
    

    and then use hunger() whenever I wanted the value instead of hungry. That way, the code doesn’t block, and we can continue doing work, but hunger() will give us the right state. E.g.

    import time
    now = time.time()
    hunger = lambda: time.time() > now + 60
    for i in range(10):
        print 'doing stuff here on loop', i
        time.sleep(10)
        print 'hunger is', hunger()
    

    produces

    doing stuff here on loop 0
    hunger is False
    doing stuff here on loop 1
    hunger is False
    doing stuff here on loop 2
    hunger is False
    doing stuff here on loop 3
    hunger is False
    doing stuff here on loop 4
    hunger is False
    doing stuff here on loop 5
    hunger is True
    doing stuff here on loop 6
    hunger is True
    doing stuff here on loop 7
    hunger is True
    doing stuff here on loop 8
    hunger is True
    doing stuff here on loop 9
    hunger is True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems like there should be... Right now it just seems like magic that you
It seems like there should be a removalAllOccuring(Collection) (or similiar) method in Multiset. A
I am used to the c-style getchar() , but it seems like there is
cgi.escape seems like one possible choice. Does it work well? Is there something that
Well is there? From everything I've read, it seems like the answer is no,but
Is there any intrinsic support for namespacing in coffeescript? Adequate namespacing seems like something
This seems if it should be fairly simple, but I'm stumbling in trying to
It seems like this should be something built into jQuery without the need for
I thought that there should have been a simple solution to this, given that
It seems like there used to be way more binary protocols because of the

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.