original_docstring: Create a db connection with connect_timeout and TCP keepalive.
      
      Default connect_timeout is 15, to change put it directly into dsn.
  
      The extra tcp_* options are Linux-specific, see `man 7 tcp` for details.
      
docstring: Create a db connection with connect_timeout and TCP keepalive.
  Default connect_timeout is 15, to change put it directly into dsn.
  
  The extra tcp_* options are Linux-specific, see `man 7 tcp` for details.
docstring_tokens: Create a db connection with connect_timeout and TCP keepalive . Default connect_timeout is 15 to change put it directly into dsn . The extra tcp_ * options are Linux - specific see ` man 7 tcp ` for details .
code: def connect_database(connstr, keepalive = True,
                       tcp_keepidle = 4 * 60,     # 7200
                       tcp_keepcnt = 4,           # 9
                       tcp_keepintvl = 15):       # 75
      """Create a db connection with connect_timeout and TCP keepalive.
      
      Default connect_timeout is 15, to change put it directly into dsn.
  
      The extra tcp_* options are Linux-specific, see `man 7 tcp` for details.
      """
  
      # allow override
      if connstr.find("connect_timeout") < 0:
          connstr += " connect_timeout=15"
  
      # create connection
      db = _CompatConnection(connstr)
      curs = db.cursor()
  
      # tune keepalive
      fd = hasattr(db, 'fileno') and db.fileno() or curs.fileno()
      set_tcp_keepalive(fd, keepalive, tcp_keepidle, tcp_keepcnt, tcp_keepintvl)
  
      # fill .server_version on older psycopg
      if not hasattr(db, 'server_version'):
          iso = db.isolation_level
          db.set_isolation_level(0)
          curs.execute('show server_version_num')
          db.server_version = int(curs.fetchone()[0])
          db.set_isolation_level(iso)
  
      return db
code_tokens: def connect_database ( connstr , keepalive = True , tcp_keepidle = 4 * 60 , tcp_keepcnt = 4 , tcp_keepintvl = 15 ) : if connstr . find ( "connect_timeout" ) < 0 : connstr += " connect_timeout=15" db = _CompatConnection ( connstr ) curs = db . cursor ( ) fd = hasattr ( db , 'fileno' ) and db . fileno ( ) or curs . fileno ( ) set_tcp_keepalive ( fd , keepalive , tcp_keepidle , tcp_keepcnt , tcp_keepintvl ) if not hasattr ( db , 'server_version' ) : iso = db . isolation_level db . set_isolation_level ( 0 ) curs . execute ( 'show server_version_num' ) db . server_version = int ( curs . fetchone ( ) [ 0 ] ) db . set_isolation_level ( iso ) return db
short_docstring: Create a db connection with connect_timeout and TCP keepalive.
short_docstring_tokens: Create a db connection with connect_timeout and TCP keepalive .
comment: # 7200$SEP$# 9$SEP$# 75$SEP$"""Create a db connection with connect_timeout and TCP keepalive.
      
      Default connect_timeout is 15, to change put it directly into dsn.
  
      The extra tcp_* options are Linux-specific, see `man 7 tcp` for details.
      """$SEP$# allow override$SEP$# create connection$SEP$# tune keepalive$SEP$# fill .server_version on older psycopg