~psycopg/psycopg/2.0.x

« back to all changes in this revision

Viewing changes to examples/threads.py

  • Committer: Federico Di Gregorio
  • Date: 2005-06-13 06:25:06 UTC
  • Revision ID: fog-fffb514a007294079bbec1acfbc081157345f9a7
psycopg->psycopg2 switch in the examples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
## don't modify anything below tis line (except for experimenting)
38
38
 
39
 
import sys, psycopg, threading
 
39
import sys, psycopg2, threading
40
40
from psycopg.pool import ThreadedConnectionPool
41
41
 
42
42
if len(sys.argv) > 1:
45
45
    MODE = int(sys.argv[2])
46
46
    
47
47
print "Opening connection using dns:", DSN
48
 
conn = psycopg.connect(DSN)
 
48
conn = psycopg2.connect(DSN)
49
49
curs = conn.cursor()
50
50
 
51
51
try:
83
83
        try:
84
84
            c.execute("INSERT INTO test_threads VALUES (%s, %s, %s)",
85
85
                      (str(i), i, float(i)))
86
 
        except psycopg.ProgrammingError, err:
 
86
        except psycopg2.ProgrammingError, err:
87
87
            print name, ": an error occurred; skipping this insert"
88
88
            print err
89
89
    conn.commit()
112
112
                    conn_or_pool.putconn(conn)
113
113
                s = name + ": number of rows fetched: " + str(len(l))
114
114
                print s
115
 
            except psycopg.ProgrammingError, err:
 
115
            except psycopg2.ProgrammingError, err:
116
116
                print name, ": an error occurred; skipping this select"
117
117
                print err
118
118
 
119
119
## create the connection pool or the connections
120
120
if MODE == 0:
121
 
    conn_insert = psycopg.connect(DSN)
122
 
    conn_select = psycopg.connect(DSN)
 
121
    conn_insert = psycopg2.connect(DSN)
 
122
    conn_select = psycopg2.connect(DSN)
123
123
else:
124
124
    m = len(INSERT_THREADS) + len(SELECT_THREADS)
125
125
    n = m/2