反复在随机点写入DataFrame崩溃的外壳程序

时间:2018-11-21 20:52:26

标签: python xml pandas lxml

背景:以下代码段遍历XML iOS备份文件线程的各个文本消息,以返回内容,发送/接收时间以及来自指定联系人的每条文本消息的方向。

                else: # if no need to chunk
                    msg_count = len(top["dict"][i]["array"][2].getchildren()) # enumerate messages
                    for n in range(msg_count): # iterate through individual messages 
                        try:
                            time = str(top["dict"][i]["array"][2]["dict"][n]["date"][0]) # fetch time
                            msg = str(top["dict"][i]["array"][2]["dict"][n]["string"][2]) # fetch content
                            if str(top["dict"][i]["array"][2]["dict"][n]["string"][4]) == 'Sent': # sent/received?
                                sent = True
                            else:
                                sent = False
                            container.loc[n] = [time, msg, sent]
                            print('Processed thread ' + str(i) + ' message ' + str(n) + '/' + str(msg_count))
                        except:
                            print('Error at thread ' + str(i) + ' message ' + str(n) + '/' + str(msg_count))

此外,以下是程序顶部初始化的变量,以供参考:

path = r'C:\Users\xxx\Documents\Python\Messages.xml'
tree = objectify.parse(path)
root = tree.getroot()
top = root.dict.array
target = ''
chunk_max = 500
container = pd.DataFrame(data=None, columns=['time', 'content', 'sent'])

发生的事情是,无论我与给定联系人有多少消息,程序都会在随机点崩溃,并且没有错误代码。对于与我有约140条消息的联系人,它崩溃于消息90左右。处理有近150,000条消息的联系人时,其挂起了约1,000条消息。它能够处理的确切文本数量有所不同。没有错误代码;我的shell崩溃并重新启动。

我尝试在Windows和Mac OS X上运行此程序,并在每个平台上都使用本机Python Shell和Spyder的iPython Shell。每种情况下都是一样的,尽管奇怪的是,它通过本机外壳中的更多消息始终如一。另外,值得注意的是,运行程序时,我的资源使用率从未达到峰值。

0 个答案:

没有答案
相关问题