當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。