Re: How to get progress in python script.
On 28 September 2012 17:26, Rolando Cañer Roblejo rolando.ca...@gmail.comwrote: Hi all, Please, I need you suggest me a way to get statistics about a progress of my python script. My python script could take a lot of time processing a file, so I need a way that an external program check the progress of the script. My first idea was that the python script write a temp file showing the progress and the external program can check that file, but I think might happen file read/write locking issues. Why does it need to be an external program? I often write python scripts that run in the terminal and spend a long time processing a file or list of files. The simply way to report progress in that case is to just print something out every now and again. When I'm feeling extravagant I use the progressbar library from PyPI: http://pypi.python.org/pypi/progressbar/ With progressbar you can get a very nice display of current progress, ETA, etc: ''' import os.path import sys from progressbar import ProgressBar, Percentage, Bar, ETA def start(text, size): widgets = [text + ' ', Percentage(), ' ', Bar(), ETA()] return ProgressBar(widgets=widgets, maxval=size).start() def process_file(path): pbar = start(os.path.basename(path), os.path.getsize(path)) with open(path) as fin: for line in fin: pbar.update(pbar.currval + len(line)) words = line.split() pbar.finish() for path in sys.argv[1:]: process_file(path) ''' Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get progress in python script.
On 28/09/2012 12:26 PM, Rolando Cañer Roblejo wrote: Hi all, Please, I need you suggest me a way to get statistics about a progress of my python script. My python script could take a lot of time processing a file, so I need a way that an external program check the progress of the script. My first idea was that the python script write a temp file showing the progress and the external program can check that file, but I think might happen file read/write locking issues. Thanks. Would the Python profiler meet your need? Colin W. -- http://mail.python.org/mailman/listinfo/python-list
How to get progress in python script.
Hi all, Please, I need you suggest me a way to get statistics about a progress of my python script. My python script could take a lot of time processing a file, so I need a way that an external program check the progress of the script. My first idea was that the python script write a temp file showing the progress and the external program can check that file, but I think might happen file read/write locking issues. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get progress in python script.
In mailman.1571.1348849432.27098.python-l...@python.org =?ISO-8859-1?Q?Rolando_Ca=F1er_Roblejo?= rolando.ca...@gmail.com writes: Hi all, Please, I need you suggest me a way to get statistics about a progress of my python script. My python script could take a lot of time processing a file, so I need a way that an external program check the progress of the script. My first idea was that the python script write a temp file showing the progress and the external program can check that file, but I think might happen file read/write locking issues. The external program should open the progress file for read only, so I wouldn't think file locking would be an issue. -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get progress in python script.
- Original Message - Hi all, Please, I need you suggest me a way to get statistics about a progress of my python script. My python script could take a lot of time processing a file, so I need a way that an external program check the progress of the script. My first idea was that the python script write a temp file showing the progress and the external program can check that file, but I think might happen file read/write locking issues. Thanks. -- http://mail.python.org/mailman/listinfo/python-list Hello, One easy way would be to use a RPC system. Pyro implements one of them. See http://packages.python.org/Pyro4/tutorials.html This could be achieved in very few lines. Your script create a thread in which it serves the remote requests. xmlrpclib is another popular RPC package. Another solution is to use a web server (sounds overkill but it isn't). A lot of python web frameworks allow you to create such server in very few lines. look at http://www.cherrypy.org/ for instance, use their 'hello word' example and replace the 'hello word' by the current script progress and you're done. JM -- http://mail.python.org/mailman/listinfo/python-list