当前位置: 首页>>代码示例>>Python>>正文


Python Pool.borrowObject方法代码示例

本文整理汇总了Python中pool.Pool.borrowObject方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.borrowObject方法的具体用法?Python Pool.borrowObject怎么用?Python Pool.borrowObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pool.Pool的用法示例。


在下文中一共展示了Pool.borrowObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestPoolFunctions

# 需要导入模块: from pool import Pool [as 别名]
# 或者: from pool.Pool import borrowObject [as 别名]
class TestPoolFunctions(unittest.TestCase):

    def setUp(self):
        self.pool = Pool(MsgPackPoolableFactory(), **config)
    def tearDown(self):
        unittest.TestCase.tearDown(self)
        self.pool.destroy()
    def test_ping(self):
        try:
            client = self.pool.borrowObject()
            self.assertIsNotNone(client, "client is None")
            rs = client.call("ping")
            self.assertEqual(rs, "pong", "is pinged")
            print rs
        finally:
            self.pool.returnObject(client)
开发者ID:wing1000,项目名称:wb3,代码行数:18,代码来源:testPool.py

示例2: Transaction

# 需要导入模块: from pool import Pool [as 别名]
# 或者: from pool.Pool import borrowObject [as 别名]
class Transaction():
    """
      基本用法1:
    ta = Transaction(dbconfig, poolConfig)

    @ta
    def test(param1,param2,db):
        return db.get("select now() as time")
    test(param1,param2)
       注意db参数在函数的 第一个

    基本用法1:
    ta=Transaction(dbconfig, poolConfig)
    def fun():
        //do something
    ta.execute(fun)

    example1:

    dbconfig = {
        "host":"127.0.0.1:4000",
        "user":"root",
        "password":"",
        "database":"test"
    }
    poolConfig = {}
    ta = Transaction(dbconfig, poolConfig)

    @ta
    def test(db):
        return db.get("select now() as time")
    @ta
    def insert(name, birthday, is_relative,db):
        return db.insert("insert into person(name,birthday,is_relative) values(%s,%s,%s)", name, birthday, is_relative)

    class Test3():
        @staticmethod
        @ta
        def test(db):
            return db.get("select now() as time")



    print test()
    from datetime import date
    print insert("x1", date.today(), 1)
    print Test3.test()


    example2:

    def test(db):
        return db.get("select now() as time")

    def test2(db):
        return db.query("select now() as time")

    class Test3():
        @staticmethod
        def test(db):
            return db.get("select now() as time")

    class Test4():
        def test(self,db):
            return db.get("select now() as time")

    t=Transaction(dbconfig, poolConfig)
    rs = t.execute(test)
    print rs.time
    rses = t.execute(test2)
    print [str(rs.time) for rs in rses]
    rs = t.execute(Test3.test)
    print rs.time
    rs = t.execute(Test4().test)
    print rs.time
    rs= t.execute(lambda db:db.get("select now() as time"))
    print rs.time
    t.destory()
    """
    
    def __init__(self, dbConfig=None, poolConfig=None, pool=None):
        '''可给定dbConfig 和poolConfig 或者pool'''
        if pool is None:
            self._pool = Pool(Torndb2PoolableFactory(**dbConfig), **poolConfig)
        else:
            self._pool = pool
            
    def destory(self):
        self._pool.destroy()  
        
    def __call__(self, func):
       
        def execute(*args,**kwargs):
            try:
                db = self._pool.borrowObject()
                a = []
                a.append(db)
                for arg in args:
                    a.append(arg)
                
#.........这里部分代码省略.........
开发者ID:wing1000,项目名称:wb3,代码行数:103,代码来源:torndb2.py


注:本文中的pool.Pool.borrowObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。