1

I'm running a long python script in the windows command line with several prints throughout my code to keep track of progress.

Right before certain prints, the python code stops running and CPU Usage just drops to zero. I can "wake up" python by hitting random keys on the keyboard with the command line window as the active window.

Using Task Manager, I can see that the CPU usage jumps, the print line processes ("Process took 219 seconds") and then the script gets going again.

Why do I have to baby monitor this file, and how can I make my code so it doesn't do this?

-CC

start = time.time()
monthsOfInterestSorted = sorted(monthsOfInterest)
if debug:
    print "calculateTradingActivity:\n\tcalculating"
tradingActivityComplete = (tsc.calculateTradingActivity(daily_volume, daily_shares, daily_dates, monthsOfInterestSorted))
if debug:
    print "\tlisting"
tradingActivityList = []
## this matrix should have unique sedol rows and date columns (date x sedol)
for sedol, date in zip(monthly_sedol_list, monthly_dates_list):
    try:
        tradingActivityList.append(tradingActivityComplete[daily_sedol.index(sedol)][monthsOfInterestSorted.index(date)])
    except ValueError:
        print "\t\tMissing trading activity data for:", sedol, date
        tradingActivityList.append('NA')
print '\tProcess took %d seconds' % (time.time()-start)
CDC
  • 51
  • 5
  • 1
    if you have an idea of where this is happening, it could help to post some code. – Jim Aug 10 '11 at 17:49
  • code posted; happens before >>> print "\tlisting" this is not the only case though. happens before i print progress. – CDC Aug 10 '11 at 18:35
  • before print "\tlisting" but after print "calculateTradingActivity:\n\tcalculating"? – Jim Aug 10 '11 at 18:52
  • yes -- but it happens in other places too, after a debug statement. CPU just drops to zero, and i have to type something into the command line to get it going again. – CDC Aug 10 '11 at 18:58
  • The answer isn't in the code you posted. There is something going on somewhere else. – agf Aug 10 '11 at 19:44
  • Tell us your OS version and Python version. Also, try to narrow down where inside tsc.calculateTradingActivity() you believe it's going to sleep, and post the code or pseudocode for that. – smci Aug 11 '11 at 22:22

0 Answers0