크기가 약 85MB 인 XML 파일을 처리하는 중입니다. 현재 나는 그것을 처리하려고하고있다. 내가하고있는 일은 zip을 다운로드하고, 디스크에 압축을 풀고, XML을 Python Dict로 변환하고, 몇 가지를 변경 한 다음, Dict를 저장하고 MongoDB로 보냅니다.큰 Dict로 작업 할 때 Python - 프로세스가 사라지고 멈춤?
나는이 스크립트를 Ubuntu 13.04 서버가 설치된 VM, 2.6 코어, 4 코어, 16GB RAM 및 1TB 15,000RPM에서 실행하고 있습니다. 본질적으로 파이썬은 7 분 동안 RAM의 12 %를 차지하고 그 다음에 프로세스가 사용률이 높은 목록에서 떨어져 내리고 터미널에서 내 파이프가 움직이지 않으면 서 스크립트를 모니터링하고 있습니다. 나는 CTRL + Z로 그것을 죽이고 "쓰기 실패 : 깨진 파이프"을 반환합니다.
터미널에 인쇄 된 마지막
이 입니다 xmltodict와 어쩌면 나를 의심 뭔가를 만드는,을 "dailyprice_0505_eur.xml.zip 변환"하지만 솔직히 붙어있어. 데이터가있는 예제 코드는 테스트 해 볼 수있는 사람이라면 누구나 사용할 수 있습니다. 어떤 도움을 주셔서 감사합니다! 감사.#Importing
import urllib, xmltodict, os
from zipfile import ZipFile
#Getting Working Dir
abspath = os.path.abspath(__file__)
root = os.path.dirname(abspath) + "/"
print "Current Working Directory: " + root
#Defining
urlAuth = 'https://dl.dropboxusercontent.com/u/9235267/'
dailypriceFL = ['dailyprice_0505_eur.xml.zip']
dailyPriceDict = {}
for x in dailyPriceFL:
print ' * Downloading',x
urllib.urlretrieve(urlAuth+x, x)
print ' * Extracting',x
with ZipFile(x, "r") as z:
z.extractall(root)
print ' * Converting',x
f = open(root+x.replace(".zip",""))
data = xmltodict.parse(f.read())
f.close()
print ' * Adding Currency to Dict',x
for y in data['prices']['price']:
y.update({"currency": x[-7:].replace(".xml","").upper()})
print ' * Ammending',x
dailyPriceDict.update(data)
print ' * Deleting',x
os.remove(root+x)
os.remove(root+x.replace(".zip",""))
print ' * Finished',x