About 1,960,000 results
Open links in new tab
  1. python - Stop code after time period - Stack Overflow

    Mar 3, 2014 · # Terminate foo p.terminate() Update 2 : Recommended. Use join with timeout. If foo finishes before timeout, then main can continue. # Wait a maximum of 10 seconds for foo # Usage: join([timeout in seconds]) p.join(10) # If thread is active if p.is_alive(): print "foo is running... let's kill it..." # Terminate foo p.terminate() p.join()

  2. Different Ways to Abort JavaScript Execution - GeeksforGeeks

    Feb 7, 2025 · Here are the different ways to abort JavaScript Execution. 1. Using return to Exit a Function. In functions, the return statement can immediately stop further execution and return a value (or undefined). 2. By throwing an Error. You can use the throw statement to interrupt execution by throwing an error.

  3. How To Exit A Function In Python? (7 Ways With Examples)

    In this blog post, we will explore various techniques and best practices to exit functions in Python effectively. We will cover different exit strategies, such as return statements, exceptions, and other control flow mechanisms, providing comprehensive explanations and examples along the way.

  4. Terminating Python Scripts: A Comprehensive Guide

    Feb 6, 2025 · In Python programming, there are various scenarios where you might need to terminate a script. Whether it's due to an error, completion of a specific task, or a need to gracefully exit the program, understanding how to terminate a Python script correctly is crucial.

  5. Python 3.10, Terminating a Long Running Function

    Mar 6, 2023 · I tried every possible way to terminate a function/script in the middle, if it runs more than 20 sec's, but not successful. Below is the function which I am using, how to exit the program/ function to force terminate if it takes more than 20 secs.

  6. python - Break the function after certain time - Stack Overflow

    Jul 30, 2014 · If you're on Mac or a Unix-based system, you should be able to use signal.SIGALRM to forcibly time out functions that take too long. This will work on functions that are idling for network or other issues that you absolutely can't handle by modifying your function.

  7. How to stop long-running code in Python - Open Source Automation

    Nov 27, 2021 · Using the timeoutable decorator is handy when you’re calling a function and want to stop its execution once a certain amount of time has been reached. The only piece of code you need to add is the decorator at the top of whatever function you want, like below.

  8. Timing Out of Long Running Methods in Python - Medium

    Nov 26, 2015 · We can make use of this functionality (only in UNIX of course) to set a timeout before a function call with the possibility to hang or take unexpected durations to finish.

  9. How to End a Program in Python - CodeRivers

    Apr 22, 2025 · The sys.exit() function is a straightforward way to terminate a Python program. It is part of the built-in sys module. Syntax import sys sys.exit([arg]) The arg parameter is optional. If provided, it can be used to return an exit status. A zero exit status typically indicates a successful termination, while non-zero values often indicate an ...

  10. How to PROPERLY exit script in Python [3 Methods]

    Dec 29, 2023 · In this tutorial, we learned about three different methods that are used to terminate the python script including exit(), quit() and sys.exit() method by taking various examples.

  11. Some results have been removed
Refresh