FAQ
Hello All,


I am looking for a library that can help me trace the status of a live
python script execution. i.e if I have a python script `x.py` with 200
lines, when I execute the script with `python x.py`, is there a way to
trace the status of this execution in terms of number of lines executed so
far?


Background: We have a Web page with "Run" button that executes the program
`x.py` when a user clicks it. We were looking of a way to keep the user
informed about the status of run by using: (no. of lines executed/total
lines) *100. Since the script `x.py` is running multiple sql queries, it
usually won't be the case that the script would complete within few seconds
of its execution.




Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20131211/71ade64e/attachment.html>

Search Discussions

  • Chris Angelico at Dec 11, 2013 at 7:34 pm

    On Thu, Dec 12, 2013 at 6:26 AM, Shyam Parimal Katti wrote:
    I am looking for a library that can help me trace the status of a live
    python script execution. i.e if I have a python script `x.py` with 200
    lines, when I execute the script with `python x.py`, is there a way to trace
    the status of this execution in terms of number of lines executed so far?

    Background: We have a Web page with "Run" button that executes the program
    `x.py` when a user clicks it. We were looking of a way to keep the user
    informed about the status of run by using: (no. of lines executed/total
    lines) *100. Since the script `x.py` is running multiple sql queries, it
    usually won't be the case that the script would complete within few seconds
    of its execution.

    That's a bit tricky. More useful would probably be to explicitly
    pepper your code with calls to some "still active" function, but it's
    going to be nearly impossible to get any sort of viable percent-done
    based on lines of code. There might be one primary loop that takes 80%
    of the execution time or more.


    You mention SQL queries. Can you wrap up the query handler in
    something that effectively treats _those_ as your fundamental
    divisions of "job-done-ness"? I'm not sure how (in either case,
    actually) you'd automatically figure out how many there are to do
    (either lines or queries), so you may still have to have something
    externally count them up - which would still not work if there's a
    loop, though with queries it's less sane to have a loop executing them
    than lines of code.


    ChrisA
  • Dan Stromberg at Dec 11, 2013 at 11:10 pm
    Long ago, I saw a C program that took another C program as input. It would
    output a copy of the original C program, interspersed with fprintf's that
    would display the text of the line current being executed.


    You might write something similar for Python, perhaps outputting the line
    being executed and/or the line number. You could have it open a file in
    /tmp or something.
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20131211/76647c1f/attachment-0001.html>
  • Ned Batchelder at Dec 12, 2013 at 10:00 pm

    On 12/11/13 2:26 PM, Shyam Parimal Katti wrote:
    Hello All,

    I am looking for a library that can help me trace the status of a live
    python script execution. i.e if I have a python script `x.py` with 200
    lines, when I execute the script with `python x.py`, is there a way to
    trace the status of this execution in terms of number of lines executed
    so far?

    Background: We have a Web page with "Run" button that executes the
    program `x.py` when a user clicks it. We were looking of a way to keep
    the user informed about the status of run by using: (no. of lines
    executed/total lines) *100. Since the script `x.py` is running multiple
    sql queries, it usually won't be the case that the script would complete
    within few seconds of its execution.

    Using sys.settrace, you could write a tool to track the lines being
    executed in any Python program. But your problem is different than that
    in two ways:


    1) You don't need to track any Python program, you need to track your
    particular Python program.


    2) You want the output to take into account the "total number of lines",
    which means you have to somehow configure it ahead of time.


    Both of these factors point to using a more specialized approach, by way
    of modifying your program. I like Chris' idea of simply tracking the
    progress of the SQL queries since they are taking the time.




    --
    Ned Batchelder, http://nedbatchelder.com

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 11, '13 at 7:26p
activeDec 12, '13 at 10:00p
posts4
users4
websitepython.org

People

Translate

site design / logo © 2023 Grokbase