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

The Archive Base Latest Questions

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

A post in 2011 answered this question for NUnit: How to unit test a

  • 0

A post in 2011 answered this question for NUnit:
How to unit test a method that runs into an infinite loop for some input?

Is there a similar TimeoutAttribute in PyUnit that I can use in the same fashion?

I did some searching and found “Duration”, but that didn’t seem the same.

  • 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-17T11:25:16+00:00Added an answer on June 17, 2026 at 11:25 am

    There doesn’t appear there is anything in pyunit itself, but as a work around you can roll your own. Here is how to do it using the multiprocessing package.

    from functools import wraps
    from multiprocessing import Process
    
    class TimeoutError(Exception):
        pass
    
    def timeout(seconds=5, error_message="Timeout"):
        def decorator(func):
            def wrapper(*args, **kwargs):
                process = Process(None, func, None, args, kwargs)
                process.start()
                process.join(seconds)
                if process.is_alive():
                    process.terminate()
                    raise TimeoutError(error_message)
    
            return wraps(func)(wrapper)
        return decorator
    

    Here is an example of how to use it:

    import time
    
    @timeout()
    def test_timeout(a, b, c):
        time.sleep(1)
    
    @timeout(1)
    def test_timeout2():
        time.sleep(2)
    
    if __name__ == '__main__':
        test_timeout(1, 2, 3)
    
        test_value = False
        try:
            test_timeout2()
        except TimeoutError as e:
            test_value = True
    
        assert test_value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some time I am worknig in MVC, I learnt from this post, http://evolpin.wordpress.com/2011/04/12/asp-net-mvc-partialview-with-ajax/#comment-435
According to author's post in version 2.0 http://lostechies.com/jimmybogard/2011/09/29/automapper-2-0-nestedchild-containers/ but this test doesnt work, can
I've been following this post http://martinciu.com/2011/01/mounting-grape-api-inside-rails-application.html I put the module into the lib directory
I've installed NVM for node.js using the instructions from this post: http://www.backdrifter.com/2011/02/18/using-nvm-and-npm-to-manage-node-js/ When I
I'm trying to follow this blog post: http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/19/wcf-extensibility-message-inspectors.aspx My aim is to somehow get
Both domain.com/blog/post/2011/01/25/This-Is-The-Post-Title!.aspx domain.com/blog/post/2011/01/25/This-Is-The-Post-Title.aspx need to be redirected to domain.com/blog/2011/01/25/this-is-the-post-title The following rule works for
I am not sure what's causing this and would love some insight: Started POST
I use this code for upload image: http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/ I replaced bm = BitmapFactory.decodeFile(/data/data/fshizzle.com/files/image.jpg); and
I tried to consolidate everything I learned about normalization in this blog post http://geekyisawesome.blogspot.com/2011/03/database-normalization-1-2-3-nf.html
178.139.20.52 - - [26/Nov/2011:08:21:13 +0000] POST /test/LinkTest.cgi?e=PATTERN&t3=0:010015&t4=1322295671:587875&l=178.139.20.174&n=149 HTTP/1.1 200 17 - BOT/1.26 Above is

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.