なんらかの理由で、プログラムが57802レコードのファイルの反復処理を停止するという問題が発生しました。ハートビートセクションを挿入して、それがどの行にあるかを確認できるようにしましたが、それが役に立ったのですが、なぜここで停止するのかがわかりません。メモリの問題だと思いましたが、6GBのメモリコンピュータで実行しただけで停止しました。
私が下でやっていることをするためのより良い方法はありますか?私の目標は、ファイルを読み取ることです(ファイルを送信する必要がある場合は、15 MBのテキストログを使用できます)。正規表現に基づいて一致するものを見つけ、一致する行を印刷します。もっと来ますが、それは私が得た限りです。私はPython2.6を使用しています
どんなアイデアでも助けになり、コメントもコーディングできます!私はPythonの初心者で、まだ学習中です。
import sys, os, os.path, operator
import re, time, fileinput
infile = os.path.join("C:\\","Python26","Scripts","stdout.log")
start = time.clock()
filename = open(infile,"r")
match = re.compile(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}),\d{3} +\w+ +\[([\w.]+)\] ((\w+).?)+:\d+ - (\w+)_SEARCH:(.+)')
count = 0
heartbeat = 0
for line in filename:
heartbeat = heartbeat + 1
print heartbeat
lookup = match.search(line)
if lookup:
count = count + 1
print line
end = time.clock()
elapsed = end-start
print "Finished processing at:",elapsed,"secs. Count of records =",count,"."
filename.close()
これは、失敗する行57802です。
2010-08-06 08:15:15,390 DEBUG [ah_admin] com.thg.struts2.SecurityInterceptor.intercept:46 - Action not SecurityAware; skipping privilege check.
これは一致する行です:
2010-08-06 09:27:29,545 INFO [patrick.phelan] com.thg.sam.actions.marketmaterial.MarketMaterialAction.result:223 - MARKET_MATERIAL_SEARCH:{"_appInfo":{"_appId":21,"_companyDivisionId":42,"_environment":"PRODUCTION"},"_description":"symlin","_createdBy":"","_fieldType":"GEO","_geoIds":["Illinois"],"_brandIds":[2883],"_archived":"ACTIVE","_expired":"UNEXPIRED","_customized":"CUSTOMIZED","_webVisible":"VISIBLE_ONLY"}
最初の5行だけのサンプルデータ:
2010-08-06 00:00:00,035 DEBUG [] com.thg.sam.jobs.PlanFormularyLoadJob.executeInternal:67 - Entered into PlanFormularyLoadJob: executeInternal
2010-08-06 00:00:00,039 DEBUG [] com.thg.ftpComponent.service.JScapeFtpService.open:153 - Opening FTP connection to sdrive/hibbert@tccfp01.hibbertnet.com:21
2010-08-06 00:00:00,040 DEBUG [] com.thg.sam.email.EmailUtils.sendEmail:206 - org.apache.commons.mail.MultiPartEmail@446e79
2010-08-06 00:00:00,045 DEBUG [] com.thg.sam.services.OrderService.getOrdersWithStatus:121 - Orders list size=13
2010-08-06 00:00:00,045 DEBUG [] com.thg.ftpComponent.service.JScapeFtpService.open:153 - Opening FTP connection to sdrive/hibbert@tccfp01.hibbertnet.com:21