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 8491729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:30:59+00:00 2026-06-10T22:30:59+00:00

I have a code: function_1() function_2() Normally, function_1() takes 10 hours to end. But

  • 0

I have a code:

function_1()
function_2()

Normally, function_1() takes 10 hours to end.
But I want function_1() to run for 2 hours, and after 2 hours, function_1 must return and program must continue with function_2(). It shouldn’t wait for function_1() to be completed. Is there a way to do this in python?

  • 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-10T22:31:01+00:00Added an answer on June 10, 2026 at 10:31 pm

    What makes functions in Python able to interrupt their execution and resuming is the use of the “yield” statement — your function then will work as a generator object. You call the “next” method on this object to have it start or continue after the last yield

    import time
    def function_1():
        start_time = time.time()
        while True:
             # do long stuff
             running_time = time.time() -start_time
             if running_time > 2 * 60 * 60: # 2 hours
                  yield #<partial results can be yield here, if you want>
                  start_time = time.time()
    
    
    
    runner = function_1()
    while True:
        try:
            runner.next()
        except StopIteration: 
            # function_1 had got to the end
            break
        # do other stuff
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to debug an application in Visual Studio but I ONLY have the
I have this code to produce a date/time picker but I only need to
I have the following code: function build_all_combinations(input_array){ array = [1,2,3] limit = array.length -
I have this jQuery code in my JSP page (jQuery 1.7.2) : function Header()
Imagine I have this code: var myFunc1 = function(event) { alert(1); } var myFunc2
For Example if i have my code like this (php): <?php somefunc(1); function somefunc($a)
Ok, I have this code: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script> <script type=text/javascript> function get()
I have this javascript code <Script> function getGroupId(){ var group=document.getElementById(selectedOptions).value; var groupFirstLetter=group.substring(2); } </Script>
I have some jQuery code: $(function(){ function someFunc(){ /*do something*/ }; ............. }); And
I have code like function populate...() { var user = $.storage.get(particulars); if (user) {

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.