2004年05月27日 星期四 09:51
不,确实是共享的。因为象mod_python或者zope之类的app serv,是在 启动的时候import所有的module的。 只要每个使用db connection的程序import的语句一样的(也就是namespace是一样的),它就不会重复import很多个的。要检验这个也很简单,只要在mysql的源代码里面链接mysql_connect()或者mysql_realconnect()里面,打印一些东西。就能看到。 -----邮件原件----- 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 The UnderTaker 发送时间: 2004年5月27日 9:45 收件人: python-chinese at lists.python.cn 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? 這樣還不是每import一次就建立一個連接嗎?它不可能永遠保持單一數據庫聯接吧 ----- Original Message ----- From: "周海文" <zhou.haiwen at gti.cn> To: <python-chinese at lists.python.cn> Sent: Thursday, May 27, 2004 9:10 AM Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > db io的效率关键是要生成一个共享的数据库联接对象(如下面的SHARE.py),然后每次访问数据库时就使用这个对象(如other.py),就减少了每次建立连接的开销。速度会明显提高很多。 > > #file: SHARE.py > import dbi,odbc,time > class DataBaseParent: > def __init__(self,strConnect): > self.strConnect=strConnect > self.db=odbc.odbc(strConnect) > > def select(self,sqlstr): > cur=self.db.cursor() > cur.execute(sqlstr) > List=cur.fetchall() > iTotal_length=len(List) > self.description=cur.description > return List,iTotal_length > > def delete(sql): > ... > > try: > dbÚtaBaseParent("ODBC_DSN_NAME/sa/sa") #关系数据库连接对象 > except: > raise 'db connect error' > > > > #file: other.py > from SHARE import db #导入数据库连接对象 > def getContent(): > lT,iNÛ.select("select * from users") > print lT,iN > > > ----- Original Message ----- > From: "Tan Lihui" <tony at exchange.ricsson.com> > To: <python-chinese at lists.python.cn> > Sent: Wednesday, May 26, 2004 7:14 PM > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > 外部方法写程序确实比较快些(是指写程序的效率高),但外部方法不是说比直接用zope api继承下来实现慢吗? > > 外部方法获取数据源,zpt做模板,模板套上数据就成了输出的html。也用了缓存和数据库连接池。我这是通常的做法,这样效率不行吗?你认为问题出在哪里?是模板语言?还是什么?我在测试的时候,db的io不是特别高,所以得出的结论是zope有问题。 > > 我相信你那个会比较快些,因为你的外部方法根本不去拿数据,数据是由一个后台程序定时去拿的。但是这样做可能只适用于实时性不要求很高的应用。对于一个论坛,大家发表了文章,没有理由要求他过一会儿才能看到自己贴的文,他会以为自己没贴成功,会继续贴了很多个同样的文章。一般都要求一发贴就能看到的..... 这些情况又没有好方法呢? > > 期待跟你交流,你是属于吃透zope的架构,并且善于根据自己应用的特点去做优化的人。 > > -----邮件原件----- > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 周海文 > 发送时间: 2004年5月26日 18:03 > 收件人: python-chinese at lists.python.cn > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > 呵呵!,不好意思,这个就是我们做的。 > 你说的对,我们基本上是全部用ZOPE中的External Method连接python程序,然后由python程序产生html输出。在ZOPE中作了缓存,有一个后台更新程序定时从数据库选择数据,然后更新到ZOPE的内存空间,python程序则直接从内存中拿数据组成动态的页面。 > > 至于共享数据库连接的问题,你可以先写一个简单的数据库连接类,然后实例化成对象,然后从其他的python程序中import这个对象,用这个对象访问数据库,就已经是共享的了。 > > 这种共享数据库连接的方法是基于python的,所以不仅在zope中可以,而且在apache+mod_python中也可以(我们有apache+mod_python的项目也是这么用的)。 > > > ----- Original Message ----- > From: "Tan Lihui" <tony at exchange.ricsson.com> > To: <python-chinese at lists.python.cn> > Sent: Wednesday, May 26, 2004 5:28 PM > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > 巨灵财经? > 怎么找人问呢? > > -----邮件原件----- > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 Jacob Fan > 发送时间: 2004年5月26日 15:55 > 收件人: python-chinese at lists.python.cn > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > ----- Original Message ----- > From: "周海文" <zhou.haiwen at gti.cn> > To: <python-chinese at lists.python.cn> > Sent: Wednesday, May 26, 2004 3:41 PM > Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > 你说zope的效率有问题,你可以看看 http://webfinance.gti.cn,这个网站目前的数据库容量已有13GB,是使用zope+python的组合,效率也不见差呀? > > > > 关于效率,我认为 apache+mod_python 是python中最快的组合。 > > 是啊,不是一般的快。 ;-) > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese -------------------------------------------------------------------------------- > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese >
2004年05月27日 星期四 10:24
python book 那些书,哪位兄弟再做种啊,好几个都卡在46.1%了:( 张峻松 zhangjunsong at ahsxhsd.com 2004-05-27
2004年05月27日 星期四 11:35
如果用Zope,写好SHARE.py之后是否要使用/Control_Panel/Products/PythonScripts 的Import功能? 还是直接在程序中Import? ----- Original Message ----- From: "Tan Lihui" <tony at exchange.ricsson.com> To: <python-chinese at lists.python.cn> Sent: Thursday, May 27, 2004 9:51 AM Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > 不,确实是共享的。因为象mod_python或者zope之类的app serv,是在 > 启动的时候import所有的module的。 > > 只要每个使用db connection的程序import的语句一样的(也就是namespace是一样的),它就不会重复import很多个的。要检验这个也很简单,只要在mysql的源代码里面链接mysql_connect()或者mysql_realconnect()里面,打印一些东西。就能看到。 > > > -----邮件原件----- > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 The UnderTaker > 发送时间: 2004年5月27日 9:45 > 收件人: python-chinese at lists.python.cn > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > 這樣還不是每import一次就建立一個連接嗎?它不可能永遠保持單一數據庫聯接吧 > > ----- Original Message ----- > From: "周海文" <zhou.haiwen at gti.cn> > To: <python-chinese at lists.python.cn> > Sent: Thursday, May 27, 2004 9:10 AM > Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > db io的效率关键是要生成一个共享的数据库联接对象(如下面的SHARE.py),然后每次访问数据库时就使用这个对象(如other.py),就减少了每次建立连接的开销。速度会明显提高很多。 > > > > #file: SHARE.py > > import dbi,odbc,time > > class DataBaseParent: > > def __init__(self,strConnect): > > self.strConnect=strConnect > > self.db=odbc.odbc(strConnect) > > > > def select(self,sqlstr): > > cur=self.db.cursor() > > cur.execute(sqlstr) > > List=cur.fetchall() > > iTotal_length=len(List) > > self.description=cur.description > > return List,iTotal_length > > > > def delete(sql): > > ... > > > > try: > > dbÚtaBaseParent("ODBC_DSN_NAME/sa/sa") #关系数据库连接对象 > > except: > > raise 'db connect error' > > > > > > > > #file: other.py > > from SHARE import db #导入数据库连接对象 > > def getContent(): > > lT,iNÛ.select("select * from users") > > print lT,iN > > > > > > ----- Original Message ----- > > From: "Tan Lihui" <tony at exchange.ricsson.com> > > To: <python-chinese at lists.python.cn> > > Sent: Wednesday, May 26, 2004 7:14 PM > > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > > > 外部方法写程序确实比较快些(是指写程序的效率高),但外部方法不是说比直接用zope api继承下来实现慢吗? > > > > 外部方法获取数据源,zpt做模板,模板套上数据就成了输出的html。也用了缓存和数据库连接池。我这是通常的做法,这样效率不行吗?你认为问题出在哪里?是模板语言?还是什么?我在测试的时候,db的io不是特别高,所以得出的结论是zope有问题。 > > > > 我相信你那个会比较快些,因为你的外部方法根本不去拿数据,数据是由一个后台程序定时去拿的。但是这样做可能只适用于实时性不要求很高的应用。对于一个论坛,大家发表了文章,没有理由要求他过一会儿才能看到自己贴的文,他会以为自己没贴成功,会继续贴了很多个同样的文章。一般都要求一发贴就能看到的..... 这些情况又没有好方法呢? > > > > 期待跟你交流,你是属于吃透zope的架构,并且善于根据自己应用的特点去做优化的人。 > > > > -----邮件原件----- > > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 周海文 > > 发送时间: 2004年5月26日 18:03 > > 收件人: python-chinese at lists.python.cn > > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > 呵呵!,不好意思,这个就是我们做的。 > > 你说的对,我们基本上是全部用ZOPE中的External Method连接python程序,然后由python程序产生html输出。在ZOPE中作了缓存,有一个后台更新程序定时从数据库选择数据,然后更新到ZOPE的内存空间,python程序则直接从内存中拿数据组成动态的页面。 > > > > 至于共享数据库连接的问题,你可以先写一个简单的数据库连接类,然后实例化成对象,然后从其他的python程序中import这个对象,用这个对象访问数据库,就已经是共享的了。 > > > > 这种共享数据库连接的方法是基于python的,所以不仅在zope中可以,而且在apache+mod_python中也可以(我们有apache+mod_python的项目也是这么用的)。 > > > > > > ----- Original Message ----- > > From: "Tan Lihui" <tony at exchange.ricsson.com> > > To: <python-chinese at lists.python.cn> > > Sent: Wednesday, May 26, 2004 5:28 PM > > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > > > 巨灵财经? > > 怎么找人问呢? > > > > -----邮件原件----- > > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 Jacob Fan > > 发送时间: 2004年5月26日 15:55 > > 收件人: python-chinese at lists.python.cn > > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > > > ----- Original Message ----- > > From: "周海文" <zhou.haiwen at gti.cn> > > To: <python-chinese at lists.python.cn> > > Sent: Wednesday, May 26, 2004 3:41 PM > > Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > > > > 你说zope的效率有问题,你可以看看 http://webfinance.gti.cn,这个网站目前的数据库容量已有13GB,是使用zope+python的组合,效率也不见差呀? > > > > > > 关于效率,我认为 apache+mod_python 是python中最快的组合。 > > > > 是啊,不是一般的快。 ;-) > > > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > > -------------------------------------------------------------------------------- > > > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > > -------------------------------------------------------------------------------- > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese >
2004年05月27日 星期四 11:47
我看例子好像是写到一个方法里,具体的跟普通python程序有哪些不同,希望指导一下,谢谢!
2004年05月27日 星期四 22:22
我已經配置好apache+mod_python了,但是import模塊來搜尋mysql數據庫還是每打開一次就新建連接,不知道哪裏錯了
----IsMysql.py-------
#!c:/python23/python.exe
# -*- coding: gbk -*-
import MySQLdb
import MySQLdb.cursors
class MysqlParent:
def __init__(self):
self.conn = MySQLdb.Connect(
host='localhost', user='UnderTaker',
passwd='djhdsfl32', db='Data',compress=1,
cursorclass=MySQLdb.cursors.DictCursor) # <- important
def runsql(self,sqlstr):
cursor = self.conn.cursor()
cursor.execute(sqlstr)
return cursor
try:
Mysql=MysqlParent() #关系数据库连接对象
except:
raise 'Mysql connect error'
----index.py-----
#!c:/python23/python.exe
# -*- coding: gbk -*-
from IsMysql import Mysql
print 'Content-Type: text/plain; charset=iso-8859-1\r\n'
Temp=Mysql.runsql('select session_user()')
Temp2=Temp.fetchone()
print str(Temp2)
Temp.close()
----apache2的httpd.conf配置python部分---
LoadModule python_module modules/mod_python.so
AddHandler mod_python .py
PythonHandler mod_python.cgihandler
PythonDebug On
AddHandler mod_python .psp
PythonHandler mod_python.psp
PythonDebug On
----- Original Message -----
From: "Tan Lihui" <tony at exchange.ricsson.com>
To: <python-chinese at lists.python.cn>
Sent: Thursday, May 27, 2004 9:51 AM
Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> 不,确实是共享的。因为象mod_python或者zope之类的app serv,是在
> 启动的时候import所有的module的。
>
> 只要每个使用db connection的程序import的语句一样的(也就是namespace是一样的),它就不会重复import很多个的。要检验这个也很简单,只要在mysql的源代码里面链接mysql_connect()或者mysql_realconnect()里面,打印一些东西。就能看到。
>
>
> -----邮件原件-----
> 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 The UnderTaker
> 发送时间: 2004年5月27日 9:45
> 收件人: python-chinese at lists.python.cn
> 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
>
> 這樣還不是每import一次就建立一個連接嗎?它不可能永遠保持單一數據庫聯接吧
>
> ----- Original Message -----
> From: "周海文" <zhou.haiwen at gti.cn>
> To: <python-chinese at lists.python.cn>
> Sent: Thursday, May 27, 2004 9:10 AM
> Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
>
>
> > db io的效率关键是要生成一个共享的数据库联接对象(如下面的SHARE.py),然后每次访问数据库时就使用这个对象(如other.py),就减少了每次建立连接的开销。速度会明显提高很多。
> >
> > #file: SHARE.py
> > import dbi,odbc,time
> > class DataBaseParent:
> > def __init__(self,strConnect):
> > self.strConnect=strConnect
> > self.db=odbc.odbc(strConnect)
> >
> > def select(self,sqlstr):
> > cur=self.db.cursor()
> > cur.execute(sqlstr)
> > List=cur.fetchall()
> > iTotal_length=len(List)
> > self.description=cur.description
> > return List,iTotal_length
> >
> > def delete(sql):
> > ...
> >
> > try:
> > dbÚtaBaseParent("ODBC_DSN_NAME/sa/sa") #关系数据库连接对象
> > except:
> > raise 'db connect error'
> >
> >
> >
> > #file: other.py
> > from SHARE import db #导入数据库连接对象
> > def getContent():
> > lT,iNÛ.select("select * from users")
> > print lT,iN
> >
> >
> > ----- Original Message -----
> > From: "Tan Lihui" <tony at exchange.ricsson.com>
> > To: <python-chinese at lists.python.cn>
> > Sent: Wednesday, May 26, 2004 7:14 PM
> > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> >
> >
> > 外部方法写程序确实比较快些(是指写程序的效率高),但外部方法不是说比直接用zope api继承下来实现慢吗?
> >
> > 外部方法获取数据源,zpt做模板,模板套上数据就成了输出的html。也用了缓存和数据库连接池。我这是通常的做法,这样效率不行吗?你认为问题出在哪里?是模板语言?还是什么?我在测试的时候,db的io不是特别高,所以得出的结论是zope有问题。
> >
> > 我相信你那个会比较快些,因为你的外部方法根本不去拿数据,数据是由一个后台程序定时去拿的。但是这样做可能只适用于实时性不要求很高的应用。对于一个论坛,大家发表了文章,没有理由要求他过一会儿才能看到自己贴的文,他会以为自己没贴成功,会继续贴了很多个同样的文章。一般都要求一发贴就能看到的..... 这些情况又没有好方法呢?
> >
> > 期待跟你交流,你是属于吃透zope的架构,并且善于根据自己应用的特点去做优化的人。
> >
> > -----邮件原件-----
> > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 周海文
> > 发送时间: 2004年5月26日 18:03
> > 收件人: python-chinese at lists.python.cn
> > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> >
> > 呵呵!,不好意思,这个就是我们做的。
> > 你说的对,我们基本上是全部用ZOPE中的External Method连接python程序,然后由python程序产生html输出。在ZOPE中作了缓存,有一个后台更新程序定时从数据库选择数据,然后更新到ZOPE的内存空间,python程序则直接从内存中拿数据组成动态的页面。
> >
> > 至于共享数据库连接的问题,你可以先写一个简单的数据库连接类,然后实例化成对象,然后从其他的python程序中import这个对象,用这个对象访问数据库,就已经是共享的了。
> >
> > 这种共享数据库连接的方法是基于python的,所以不仅在zope中可以,而且在apache+mod_python中也可以(我们有apache+mod_python的项目也是这么用的)。
> >
> >
> > ----- Original Message -----
> > From: "Tan Lihui" <tony at exchange.ricsson.com>
> > To: <python-chinese at lists.python.cn>
> > Sent: Wednesday, May 26, 2004 5:28 PM
> > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> >
> >
> > 巨灵财经?
> > 怎么找人问呢?
> >
> > -----邮件原件-----
> > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 Jacob Fan
> > 发送时间: 2004年5月26日 15:55
> > 收件人: python-chinese at lists.python.cn
> > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> >
> >
> > ----- Original Message -----
> > From: "周海文" <zhou.haiwen at gti.cn>
> > To: <python-chinese at lists.python.cn>
> > Sent: Wednesday, May 26, 2004 3:41 PM
> > Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> >
> >
> > > 你说zope的效率有问题,你可以看看 http://webfinance.gti.cn,这个网站目前的数据库容量已有13GB,是使用zope+python的组合,效率也不见差呀?
> > >
> > > 关于效率,我认为 apache+mod_python 是python中最快的组合。
> >
> > 是啊,不是一般的快。 ;-)
> >
> > _______________________________________________
> > python-chinese list
> > python-chinese at lists.python.cn
> > http://python.cn/mailman/listinfo/python-chinese
> >
> > _______________________________________________
> > python-chinese list
> > python-chinese at lists.python.cn
> > http://python.cn/mailman/listinfo/python-chinese
>
>
> --------------------------------------------------------------------------------
>
>
> > _______________________________________________
> > python-chinese list
> > python-chinese at lists.python.cn
> > http://python.cn/mailman/listinfo/python-chinese
> >
>
--------------------------------------------------------------------------------
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
>
2004年05月28日 星期五 16:40
在ZOPE中: ZOPE中的外部方法(Extenal Method)中,可以直接from SHARE import db。这个import进来的db是共享的,不会每次访问都重新连接。ZOPE中的PythonScript只能完成一些简单的功能,最好用 Extenal Method连接 *.py 来完成复杂的任务。 在apache中: apache中的用法一样,只是 httpd.conf 配置文件要注意,最后一行要将 SHARE 指定为常住模块(内置python解释器启动时就将SHARE导入),详见mod_python的文档。最好下载最新的apache和mod_python #file:httpd.conf LoadModule python_module modules/mod_python.soAddHandler python-program .py PythonHandler wap PythonDebug On PythonImport SHARE lt_wap 另外我看见你好像在用cgihandler,cgi很可能是每次都需启动python解释环境,并且重建db连接,cgi的效率很低,建议不要使用。 ----- Original Message ----- From: "The UnderTaker" <undertaker at i-cable.com> To: <python-chinese at lists.python.cn> Sent: Thursday, May 27, 2004 10:22 PM Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > 我已經配置好apache+mod_python了,但是import模塊來搜尋mysql數據庫還是每打開一次就新建連接,不知道哪裏錯了 > ----IsMysql.py------- > #!c:/python23/python.exe > # -*- coding: gbk -*- > import MySQLdb > import MySQLdb.cursors > class MysqlParent: > def __init__(self): > self.conn = MySQLdb.Connect( > host='localhost', user='UnderTaker', > passwd='djhdsfl32', db='Data',compress=1, > cursorclass=MySQLdb.cursors.DictCursor) # <- important > > def runsql(self,sqlstr): > cursor = self.conn.cursor() > cursor.execute(sqlstr) > return cursor > > try: > Mysql=MysqlParent() #关系数据库连接对象 > except: > raise 'Mysql connect error' > > > ----index.py----- > #!c:/python23/python.exe > # -*- coding: gbk -*- > from IsMysql import Mysql > print 'Content-Type: text/plain; charset=iso-8859-1\r\n' > Temp=Mysql.runsql('select session_user()') > Temp2=Temp.fetchone() > print str(Temp2) > Temp.close() > > ----apache2的httpd.conf配置python部分--- > LoadModule python_module modules/mod_python.so >> AddHandler mod_python .py > PythonHandler mod_python.cgihandler > PythonDebug On > > > > AddHandler mod_python .psp > PythonHandler mod_python.psp > PythonDebug On > > > > ----- Original Message ----- > From: "Tan Lihui" <tony at exchange.ricsson.com> > To: <python-chinese at lists.python.cn> > Sent: Thursday, May 27, 2004 9:51 AM > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > 不,确实是共享的。因为象mod_python或者zope之类的app serv,是在 > > 启动的时候import所有的module的。 > > > > 只要每个使用db connection的程序import的语句一样的(也就是namespace是一样的),它就不会重复import很多个的。要检验这个也很简单,只要在mysql的源代码里面链接mysql_connect()或者mysql_realconnect()里面,打印一些东西。就能看到。 > > > > > > -----邮件原件----- > > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 The UnderTaker > > 发送时间: 2004年5月27日 9:45 > > 收件人: python-chinese at lists.python.cn > > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > 這樣還不是每import一次就建立一個連接嗎?它不可能永遠保持單一數據庫聯接吧 > > > > ----- Original Message ----- > > From: "周海文" <zhou.haiwen at gti.cn> > > To: <python-chinese at lists.python.cn> > > Sent: Thursday, May 27, 2004 9:10 AM > > Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > > > > db io的效率关键是要生成一个共享的数据库联接对象(如下面的SHARE.py),然后每次访问数据库时就使用这个对象(如other.py),就减少了每次建立连接的开销。速度会明显提高很多。 > > > > > > #file: SHARE.py > > > import dbi,odbc,time > > > class DataBaseParent: > > > def __init__(self,strConnect): > > > self.strConnect=strConnect > > > self.db=odbc.odbc(strConnect) > > > > > > def select(self,sqlstr): > > > cur=self.db.cursor() > > > cur.execute(sqlstr) > > > List=cur.fetchall() > > > iTotal_length=len(List) > > > self.description=cur.description > > > return List,iTotal_length > > > > > > def delete(sql): > > > ... > > > > > > try: > > > dbÚtaBaseParent("ODBC_DSN_NAME/sa/sa") #关系数据库连接对象 > > > except: > > > raise 'db connect error' > > > > > > > > > > > > #file: other.py > > > from SHARE import db #导入数据库连接对象 > > > def getContent(): > > > lT,iNÛ.select("select * from users") > > > print lT,iN > > > > > > > > > ----- Original Message ----- > > > From: "Tan Lihui" <tony at exchange.ricsson.com> > > > To: <python-chinese at lists.python.cn> > > > Sent: Wednesday, May 26, 2004 7:14 PM > > > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > > > > > > 外部方法写程序确实比较快些(是指写程序的效率高),但外部方法不是说比直接用zope api继承下来实现慢吗? > > > > > > 外部方法获取数据源,zpt做模板,模板套上数据就成了输出的html。也用了缓存和数据库连接池。我这是通常的做法,这样效率不行吗?你认为问题出在哪里?是模板语言?还是什么?我在测试的时候,db的io不是特别高,所以得出的结论是zope有问题。 > > > > > > 我相信你那个会比较快些,因为你的外部方法根本不去拿数据,数据是由一个后台程序定时去拿的。但是这样做可能只适用于实时性不要求很高的应用。对于一个论坛,大家发表了文章,没有理由要求他过一会儿才能看到自己贴的文,他会以为自己没贴成功,会继续贴了很多个同样的文章。一般都要求一发贴就能看到的..... 这些情况又没有好方法呢? > > > > > > 期待跟你交流,你是属于吃透zope的架构,并且善于根据自己应用的特点去做优化的人。 > > > > > > -----邮件原件----- > > > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 周海文 > > > 发送时间: 2004年5月26日 18:03 > > > 收件人: python-chinese at lists.python.cn > > > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > > > 呵呵!,不好意思,这个就是我们做的。 > > > 你说的对,我们基本上是全部用ZOPE中的External Method连接python程序,然后由python程序产生html输出。在ZOPE中作了缓存,有一个后台更新程序定时从数据库选择数据,然后更新到ZOPE的内存空间,python程序则直接从内存中拿数据组成动态的页面。 > > > > > > 至于共享数据库连接的问题,你可以先写一个简单的数据库连接类,然后实例化成对象,然后从其他的python程序中import这个对象,用这个对象访问数据库,就已经是共享的了。 > > > > > > 这种共享数据库连接的方法是基于python的,所以不仅在zope中可以,而且在apache+mod_python中也可以(我们有apache+mod_python的项目也是这么用的)。 > > > > > > > > > ----- Original Message ----- > > > From: "Tan Lihui" <tony at exchange.ricsson.com> > > > To: <python-chinese at lists.python.cn> > > > Sent: Wednesday, May 26, 2004 5:28 PM > > > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > > > > > > 巨灵财经? > > > 怎么找人问呢? > > > > > > -----邮件原件----- > > > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 Jacob Fan > > > 发送时间: 2004年5月26日 15:55 > > > 收件人: python-chinese at lists.python.cn > > > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > > > > > > ----- Original Message ----- > > > From: "周海文" <zhou.haiwen at gti.cn> > > > To: <python-chinese at lists.python.cn> > > > Sent: Wednesday, May 26, 2004 3:41 PM > > > Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序? > > > > > > > > > > 你说zope的效率有问题,你可以看看 http://webfinance.gti.cn,这个网站目前的数据库容量已有13GB,是使用zope+python的组合,效率也不见差呀? > > > > > > > > 关于效率,我认为 apache+mod_python 是python中最快的组合。 > > > > > > 是啊,不是一般的快。 ;-) > > > > > > _______________________________________________ > > > python-chinese list > > > python-chinese at lists.python.cn > > > http://python.cn/mailman/listinfo/python-chinese > > > > > > _______________________________________________ > > > python-chinese list > > > python-chinese at lists.python.cn > > > http://python.cn/mailman/listinfo/python-chinese > > > > > > -------------------------------------------------------------------------------- > > > > > > > _______________________________________________ > > > python-chinese list > > > python-chinese at lists.python.cn > > > http://python.cn/mailman/listinfo/python-chinese > > > > > > > > -------------------------------------------------------------------------------- > > > > _______________________________________________ > > python-chinese list > > python-chinese at lists.python.cn > > http://python.cn/mailman/listinfo/python-chinese > > -------------------------------------------------------------------------------- > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese >
2004年05月28日 星期五 17:36
Mod_python error: "PythonHandler wap"
Traceback (most recent call last):
File "C:\Python23\Lib\site-packages\mod_python\apache.py", line 287, in HandlerDispatch
log=debug)
File "C:\Python23\Lib\site-packages\mod_python\apache.py", line 454, in import_module
f, p, d = imp.find_module(parts[i], path)
ImportError: No module named wap
是不是沒有這個模塊文件?
----- Original Message -----
From: "周海文" <zhou.haiwen at gti.cn>
To: <python-chinese at lists.python.cn>
Sent: Friday, May 28, 2004 4:40 PM
Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> 在ZOPE中:
> ZOPE中的外部方法(Extenal Method)中,可以直接from SHARE import db。这个import进来的db是共享的,不会每次访问都重新连接。ZOPE中的PythonScript只能完成一些简单的功能,最好用 Extenal Method连接 *.py 来完成复杂的任务。
>
> 在apache中:
> apache中的用法一样,只是 httpd.conf 配置文件要注意,最后一行要将 SHARE 指定为常住模块(内置python解释器启动时就将SHARE导入),详见mod_python的文档。最好下载最新的apache和mod_python
>
> #file:httpd.conf
> LoadModule python_module modules/mod_python.so
>
>
> AddHandler python-program .py
> PythonHandler wap
> PythonDebug On
>
>
> PythonImport SHARE lt_wap
>
> 另外我看见你好像在用cgihandler,cgi很可能是每次都需启动python解释环境,并且重建db连接,cgi的效率很低,建议不要使用。
>
> ----- Original Message -----
> From: "The UnderTaker" <undertaker at i-cable.com>
> To: <python-chinese at lists.python.cn>
> Sent: Thursday, May 27, 2004 10:22 PM
> Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
>
>
> > 我已經配置好apache+mod_python了,但是import模塊來搜尋mysql數據庫還是每打開一次就新建連接,不知道哪裏錯了
> > ----IsMysql.py-------
> > #!c:/python23/python.exe
> > # -*- coding: gbk -*-
> > import MySQLdb
> > import MySQLdb.cursors
> > class MysqlParent:
> > def __init__(self):
> > self.conn = MySQLdb.Connect(
> > host='localhost', user='UnderTaker',
> > passwd='djhdsfl32', db='Data',compress=1,
> > cursorclass=MySQLdb.cursors.DictCursor) # <- important
> >
> > def runsql(self,sqlstr):
> > cursor = self.conn.cursor()
> > cursor.execute(sqlstr)
> > return cursor
> >
> > try:
> > Mysql=MysqlParent() #关系数据库连接对象
> > except:
> > raise 'Mysql connect error'
> >
> >
> > ----index.py-----
> > #!c:/python23/python.exe
> > # -*- coding: gbk -*-
> > from IsMysql import Mysql
> > print 'Content-Type: text/plain; charset=iso-8859-1\r\n'
> > Temp=Mysql.runsql('select session_user()')
> > Temp2=Temp.fetchone()
> > print str(Temp2)
> > Temp.close()
> >
> > ----apache2的httpd.conf配置python部分---
> > LoadModule python_module modules/mod_python.so
> >
> > AddHandler mod_python .py
> > PythonHandler mod_python.cgihandler
> > PythonDebug On
> >
> >
> >
> > AddHandler mod_python .psp
> > PythonHandler mod_python.psp
> > PythonDebug On
> >
> >
> >
> > ----- Original Message -----
> > From: "Tan Lihui" <tony at exchange.ricsson.com>
> > To: <python-chinese at lists.python.cn>
> > Sent: Thursday, May 27, 2004 9:51 AM
> > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> >
> >
> > > 不,确实是共享的。因为象mod_python或者zope之类的app serv,是在
> > > 启动的时候import所有的module的。
> > >
> > > 只要每个使用db connection的程序import的语句一样的(也就是namespace是一样的),它就不会重复import很多个的。要检验这个也很简单,只要在mysql的源代码里面链接mysql_connect()或者mysql_realconnect()里面,打印一些东西。就能看到。
> > >
> > >
> > > -----邮件原件-----
> > > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 The UnderTaker
> > > 发送时间: 2004年5月27日 9:45
> > > 收件人: python-chinese at lists.python.cn
> > > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> > >
> > > 這樣還不是每import一次就建立一個連接嗎?它不可能永遠保持單一數據庫聯接吧
> > >
> > > ----- Original Message -----
> > > From: "周海文" <zhou.haiwen at gti.cn>
> > > To: <python-chinese at lists.python.cn>
> > > Sent: Thursday, May 27, 2004 9:10 AM
> > > Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> > >
> > >
> > > > db io的效率关键是要生成一个共享的数据库联接对象(如下面的SHARE.py),然后每次访问数据库时就使用这个对象(如other.py),就减少了每次建立连接的开销。速度会明显提高很多。
> > > >
> > > > #file: SHARE.py
> > > > import dbi,odbc,time
> > > > class DataBaseParent:
> > > > def __init__(self,strConnect):
> > > > self.strConnect=strConnect
> > > > self.db=odbc.odbc(strConnect)
> > > >
> > > > def select(self,sqlstr):
> > > > cur=self.db.cursor()
> > > > cur.execute(sqlstr)
> > > > List=cur.fetchall()
> > > > iTotal_length=len(List)
> > > > self.description=cur.description
> > > > return List,iTotal_length
> > > >
> > > > def delete(sql):
> > > > ...
> > > >
> > > > try:
> > > > dbÚtaBaseParent("ODBC_DSN_NAME/sa/sa") #关系数据库连接对象
> > > > except:
> > > > raise 'db connect error'
> > > >
> > > >
> > > >
> > > > #file: other.py
> > > > from SHARE import db #导入数据库连接对象
> > > > def getContent():
> > > > lT,iNÛ.select("select * from users")
> > > > print lT,iN
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Tan Lihui" <tony at exchange.ricsson.com>
> > > > To: <python-chinese at lists.python.cn>
> > > > Sent: Wednesday, May 26, 2004 7:14 PM
> > > > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> > > >
> > > >
> > > > 外部方法写程序确实比较快些(是指写程序的效率高),但外部方法不是说比直接用zope api继承下来实现慢吗?
> > > >
> > > > 外部方法获取数据源,zpt做模板,模板套上数据就成了输出的html。也用了缓存和数据库连接池。我这是通常的做法,这样效率不行吗?你认为问题出在哪里?是模板语言?还是什么?我在测试的时候,db的io不是特别高,所以得出的结论是zope有问题。
> > > >
> > > > 我相信你那个会比较快些,因为你的外部方法根本不去拿数据,数据是由一个后台程序定时去拿的。但是这样做可能只适用于实时性不要求很高的应用。对于一个论坛,大家发表了文章,没有理由要求他过一会儿才能看到自己贴的文,他会以为自己没贴成功,会继续贴了很多个同样的文章。一般都要求一发贴就能看到的..... 这些情况又没有好方法呢?
> > > >
> > > > 期待跟你交流,你是属于吃透zope的架构,并且善于根据自己应用的特点去做优化的人。
> > > >
> > > > -----邮件原件-----
> > > > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 周海文
> > > > 发送时间: 2004年5月26日 18:03
> > > > 收件人: python-chinese at lists.python.cn
> > > > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> > > >
> > > > 呵呵!,不好意思,这个就是我们做的。
> > > > 你说的对,我们基本上是全部用ZOPE中的External Method连接python程序,然后由python程序产生html输出。在ZOPE中作了缓存,有一个后台更新程序定时从数据库选择数据,然后更新到ZOPE的内存空间,python程序则直接从内存中拿数据组成动态的页面。
> > > >
> > > > 至于共享数据库连接的问题,你可以先写一个简单的数据库连接类,然后实例化成对象,然后从其他的python程序中import这个对象,用这个对象访问数据库,就已经是共享的了。
> > > >
> > > > 这种共享数据库连接的方法是基于python的,所以不仅在zope中可以,而且在apache+mod_python中也可以(我们有apache+mod_python的项目也是这么用的)。
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Tan Lihui" <tony at exchange.ricsson.com>
> > > > To: <python-chinese at lists.python.cn>
> > > > Sent: Wednesday, May 26, 2004 5:28 PM
> > > > Subject: 答复: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> > > >
> > > >
> > > > 巨灵财经?
> > > > 怎么找人问呢?
> > > >
> > > > -----邮件原件-----
> > > > 发件人: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] 代表 Jacob Fan
> > > > 发送时间: 2004年5月26日 15:55
> > > > 收件人: python-chinese at lists.python.cn
> > > > 主题: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "周海文" <zhou.haiwen at gti.cn>
> > > > To: <python-chinese at lists.python.cn>
> > > > Sent: Wednesday, May 26, 2004 3:41 PM
> > > > Subject: Re: [python-chinese]如何写一个用Web形式浏览一次,就能常住内存的程序?
> > > >
> > > >
> > > > > 你说zope的效率有问题,你可以看看 http://webfinance.gti.cn,这个网站目前的数据库容量已有13GB,是使用zope+python的组合,效率也不见差呀?
> > > > >
> > > > > 关于效率,我认为 apache+mod_python 是python中最快的组合。
> > > >
> > > > 是啊,不是一般的快。 ;-)
> > > >
> > > > _______________________________________________
> > > > python-chinese list
> > > > python-chinese at lists.python.cn
> > > > http://python.cn/mailman/listinfo/python-chinese
> > > >
> > > > _______________________________________________
> > > > python-chinese list
> > > > python-chinese at lists.python.cn
> > > > http://python.cn/mailman/listinfo/python-chinese
> > >
> > >
> > > --------------------------------------------------------------------------------
> > >
> > >
> > > > _______________________________________________
> > > > python-chinese list
> > > > python-chinese at lists.python.cn
> > > > http://python.cn/mailman/listinfo/python-chinese
> > > >
> > >
> >
> >
> > --------------------------------------------------------------------------------
> >
> >
> > > _______________________________________________
> > > python-chinese list
> > > python-chinese at lists.python.cn
> > > http://python.cn/mailman/listinfo/python-chinese
> > >
>
>
> --------------------------------------------------------------------------------
>
>
> > _______________________________________________
> > python-chinese list
> > python-chinese at lists.python.cn
> > http://python.cn/mailman/listinfo/python-chinese
> >
--------------------------------------------------------------------------------
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
>
Zeuux © 2025
京ICP备05028076号