Python sleeps until keystroke

落花浮王杯 提交于 2019-12-24 08:22:31

问题


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)

来源:https://stackoverflow.com/questions/7015322/python-sleeps-until-keystroke

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!