简体   繁体   English

Python2.6 XML阅读

[英]Python2.6 XML reading

I want to migrate my system from Active Python 2.4 to Python 2.6.5. 我想将系统从Active Python 2.4迁移到Python 2.6.5。 However I face some problem in parsing XML files. 但是,我在解析XML文件时遇到一些问题。 The I/O is very slow. I / O非常慢。

My sample xml file 我的样本xml文件

<config><dicts><dictName>EnvDict</dictName><dictElems><key>AppServerIP</key>  <value>localhost</value><key>DBServerIP</key>   <value>localhost</value><key>DBServerName</key> <value>DB1</value></dictElems></dicts></config>

My log shows this xml parsing took 25s. 我的日志显示此xml解析耗时25s。

My system is structure as below 我的系统结构如下

Publisher-Subr is used to redirect request to different modules Publisher-Subr用于将请求重定向到不同的模块

ClntMgrFact is attached to PubSubr and listen to pre-defined ports. ClntMgrFact附加到PubSubr,并侦听预定义的端口。 It will spawn a new process for login from client. 它将产生一个新的从客户端登录的过程。

ClntMgr(process) is spawned by ClntMgrFact and also attached to PubSubr. ClntMgr(process)由ClntMgrFact生成,并且也附加到PubSubr。 ClntMgr will generate a ClntWorker(thread) to process workflow. ClntMgr将生成一个ClntWorker(thread)来处理工作流。

ClntWorker need to read some static XML file from local . ClntWorker需要从本地读取一些静态XML文件 But the parsing is extremely slow. 但是解析非常慢。 My XML file is around 500 - 700k. 我的XML文件大约是500-700k。

Any one can help on this without changing the system structure? 任何人都可以在不更改系统结构的情况下提供帮助吗? Thanks in advance. 提前致谢。

I'm very perplexed...: 困惑...:

$ py26 -mtimeit -s'import rex' 'rex.t()'
10000 loops, best of 3: 103 usec per loop

100 microseconds seems more reasonable than 25 seconds to read in, and parse, such a small XML file as you're giving (even on the old laptop I'm using for the timing!) -- but how to explain the fact that my parsing is being 250,000 times faster than yours?! 100微秒似乎比25秒更合理的方式来读取和解析您所提供的小XML文件(即使在我用于计时的旧笔记本电脑上也是如此!),但是如何解释我解析速度比您快25万倍吗?

This is rex.py , btw...: 这是rex.py ,顺便说rex.py ...:

import xml.etree.cElementTree as et

def t(fn='static.xml'):
  return et.parse(fn)

and static.xml is the file where I wrote your XML example (223 characters). static.xml是我编写XML示例的文件(223个字符)。

So what's your platform, OS, Python version, chosen XML parser, etc...? 那么您的平台,操作系统,Python版本,选择的XML解析器等是什么? I'm on a macbook pro laptop, OSX 10.5.8, 2.4 GHz Intel Core Duo, 667 MHz DDR2 RAM -- as I said, a pretty old machine indeed! 我使用的是Macbook Pro笔记本电脑,OSX 10.5.8、2.4 GHz Intel Core Duo,667 MHz DDR2 RAM-正如我所说,确实是一台相当老的机器! -- with Python 2.6.4 straight from python.org. -直接来自python.org的Python 2.6.4。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM