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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:07:09+00:00 2026-06-02T16:07:09+00:00

I would need to run a python script for some random amount of time,

  • 0

I would need to run a python script for some random amount of time, pause it, get a stack traceback, and unpause it. I’ve googled around for a way to do this, but I see no obvious solution.

  • 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-02T16:07:11+00:00Added an answer on June 2, 2026 at 4:07 pm

    There’s the statprof module

    pip install statprof (or easy_install statprof), then to use:

    import statprof
    
    statprof.start()
    try:
        my_questionable_function()
    finally:
        statprof.stop()
        statprof.display()
    

    There’s a bit of background on the module from this blog post:

    Why would this matter, though? Python already has two built-in profilers: lsprof and the long-deprecated hotshot. The trouble with lsprof is that it only tracks function calls. If you have a few hot loops within a function, lsprof is nearly worthless for figuring out which ones are actually important.

    A few days ago, I found myself in exactly the situation in which lsprof fails: it was telling me that I had a hot function, but the function was unfamiliar to me, and long enough that it wasn’t immediately obvious where the problem was.

    After a bit of begging on Twitter and Google+, someone pointed me at statprof. But there was a problem: although it was doing statistical sampling (yay!), it was only tracking the first line of a function when sampling (wtf!?). So I fixed that, spiffed up the documentation, and now it’s both usable and not misleading. Here’s an example of its output, locating the offending line in that hot function more accurately:

      %   cumulative      self          
     time    seconds   seconds  name    
     68.75      0.14      0.14  scmutil.py:546:revrange
      6.25      0.01      0.01  cmdutil.py:1006:walkchangerevs
      6.25      0.01      0.01  revlog.py:241:__init__
      [...blah blah blah...]
      0.00      0.01      0.00  util.py:237:__get__
    ---
    Sample count: 16
    Total time: 0.200000 seconds
    

    I have uploaded statprof to the Python package index, so it’s almost trivial to install: “easy_install statprof” and you’re up and running.

    Since the code is up on github, please feel welcome to contribute bug reports and improvements. Enjoy!

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

Sidebar

Related Questions

I would need some help in python. I'm new in python. I used to
A python script I need to run takes input only from a file passed
I have a python script that runs a subprocess to get some data and
I would need some basic vector mathematics constructs in an application. Dot product, cross
I would need to get a Regular Expression, which matches all Unicode control characters
I would need a readonly / unmodifiable java.util.Stack . For List s there is
So I wrote a Python script which does some simple stuff. It was originally
I need to create some way to get a local WAR file deployed on
I have a python web application and I would like to run multiple scripts
I am writing a CGI script in python 2.5 and I have run into

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.