日期:2014-05-16  浏览次数:20413 次

解决MySQLdb导入时报出“不推荐继续使用的Sets模块”的问题

问题暴露:

客户端第一次访问时,总会卡上1——2s才能获得数据,之后再访问时就没有问题了。

?

问题解决:

在eclipse的django shell模式下测试服务端写的一些接口,在调用需要从数据库查询数据的方法时, 也出现了卡了1——2s的情况,然后提示:

the sets module is deprecated

?

这才意识到,是这个在python2.6中不推荐使用的sets模块导致了问题。

经过查询python2.6的手册:

?

Deprecated since version 2.6: The built-in set/frozenset types replace this module.

即:这个模块2.6版本中已不推荐使用,替代它的是内置的 set 和 frozenset 类型。

?

修改mysqldb/__init__.py文件,将:

?

 from sets import ImmutableSet
class DBAPISet(ImmutableSet):

    """A special type of set for which A == x is true if A is a
    DBAPISet and x is a member of that set."""

? 改为:

?

# from sets import ImmutableSet
class DBAPISet(frozenset):

    """A special type of set for which A == x is true if A is a
    DBAPISet and x is a member of that set."""
?

?

问题解决。