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


Python Pool.get方法代码示例

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


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

示例1: file

# 需要导入模块: from pool import Pool [as 别名]
# 或者: from pool.Pool import get [as 别名]
                input = file(val, "r")
        elif opt in ('-s', '--strict'):
            opt_strict = True
        elif opt in ('-q', '--quiet'):
            opt_quiet = True
        elif opt in ('-t', '--tree'):
            opt_tree = True

    pool = Pool()
    
    if input:
        packages += read_packages(input)

    if not args[1:] and not input:
        # if no packages specified, get all the newest versions
        packages = pool.list()

    try:
        packages = pool.get(outputdir, packages, tree_fmt=opt_tree, strict=opt_strict)
    except pool.Error, e:
        fatal(e)

    if not opt_quiet:
        for package in packages.missing:
            warn("no such package (%s)" % package)
            
    sys.exit(exitcode)
        
if __name__=="__main__":
    main()
开发者ID:qrntz,项目名称:pool,代码行数:32,代码来源:cmd_get.py

示例2: DB

# 需要导入模块: from pool import Pool [as 别名]
# 或者: from pool.Pool import get [as 别名]
class DB(object):
  "manage pooled database access"
  def __init__(self, connect_config=None):
    """set up connection pool if config is available.
       This allows the legacy pattern of app setup
       by calling init_db to continue.
    """
    if connect_config:
      self.init(connect_config)

  def init(self, connect_config):
    "set up connection pools"
    # allow for legacy config
    # - check for space and comma delimited strings
    if type(connect_config) == str:
      if ',' in connect_config:
        delim = ','
      else:
        delim = ' '
      connect_config = connect_config.split(delim)
      print ('Deprecated: database connection should be a tuple not a string')

    host, user, pw = connect_config
    self.conn_pool = Pool(Constructor(self.connect
                                      , host, user, pw
                                      , charset='utf8'), poolsize=8)
    self.async_pool = adbapi.ConnectionPool('MySQLdb'
                                            , host, user, pw
                                            , charset='utf8'
                                            , cursorclass=DictCursor)

  def execute(self, sql, args=None):
    "perform a query safely"
    dbc = self.conn_pool.get()
    db = dbc.cursor(DictCursor)
    try:
      db.execute(sql, args)
    except OperationalError:
      dbc = self.conn_pool.get()
      db = dbc.cursor(DictCursor)
      db.execute(sql, args)

    if 'INSERT' in sql.upper():
      # return the insert id
      res = dbc.insert_id()
    else:
      # return the result seT
      res = db.fetchall()
    db.close()
    # Disconnect(dbc)
    self.conn_pool.put(dbc)
    del db, dbc
    return res

  @inlineCallbacks
  def aexecute(self, sql, *params):
    "execute query asyncrously"

    if 'INSERT' in sql.upper():
      # for INSERT we would like to return the insert id
      def insert(db):
        "insert a record, return its insert id"
        db.execute(sql, params)
        return db.connection.insert_id()
      uid = yield self.async_pool.runInteraction(insert)
      returnValue(uid)
    else:
      l = yield self.async_pool.runQuery(sql, *params)
      returnValue(l)

  def connect(self, *args, **kwargs):
    "connect to MySQL and intialise connection. Used by syncrous interface"
    dbc = MySQLconnect(*args, **kwargs)
    # override this method to give the required answer at all times!
    dbc.character_set_name = lambda: 'utf8'
    return dbc
开发者ID:mrcjhurst,项目名称:evoke,代码行数:78,代码来源:DB.py


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