Python Forum
cProfile debugging - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: cProfile debugging (/thread-19684.html)



cProfile debugging - fakka - Jul-10-2019

Have some basic code that loops through a set of databases and assigns a count to a python list.
At end I just make a sum of that python list.
The sum seems to be where its really slow - which is strange as the list size is only around 10.

#code
import os
#import cProfile
from subprocess import Popen, PIPE

totalram=[]

lst = os.popen("ps -eaf | grep pmon | grep -iv $$ | egrep -iv 'ASM|APX' | sed 's?ora_pmon_??g' | awk '{print $NF}'").read()
lst = lst.split('\n')
for each in lst:
        sqlplus = Popen(["sqlplus", "-S", "/", "as", "sysdba"], stdout=PIPE, stdin=PIPE)
        sqlplus.stdin.write("set head off;"+os.linesep)
        sqlplus.stdin.write("select count(*) from all_objects;"+os.linesep)
        out ,err= sqlplus.communicate()
        print out
        totalram.append(int(out))

print (sum(totalram))
54 0.000 0.000 0.000 0.000 subprocess.py:772(_check_timeout)
1 0.000 0.000 0.000 0.000 traceback.py:1(<module>)
1 0.000 0.000 0.000 0.000 {_sre.compile}
118 0.000 0.000 0.000 0.000 {built-in method match}
54 7.453 0.138 7.453 0.138 {built-in method poll} <====== SLOW here - but what to do about it ?
27 0.000 0.000 0.000 0.000 {built-in method register}
27 0.000 0.000 0.000 0.000 {built-in method unregister}
1 0.000 0.000 0.000 0.000 {dir}

nevermind ....... it just "appeared" on my screen it was slow on the SUM function.
Its just slow on the loop iteration.

Anyone got a good link/video/url for debugging python errors outside of PDB .... I use pycharm but newbie