mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 09:24:07 +03:00
Some more tests in sandbox.
This commit is contained in:
parent
1aed516938
commit
5871596eda
7
NEWS
7
NEWS
|
@ -8,6 +8,13 @@ What's new in psycopg 2.0 beta 7
|
|||
* Slightly better ZPsycopgDA (no more double connection objects in the menu
|
||||
and other minor fixes.)
|
||||
|
||||
* ProgrammingError exceptions now have three extra attributes: .cursor
|
||||
(it is possible to access the query that caused the exception using
|
||||
error.cursor.query), .pgerror and .pgcode (PostgreSQL original error
|
||||
text and code.)
|
||||
|
||||
* The build system uses pg_config when available.
|
||||
|
||||
* Documentation in the doc/ directory! (With many kudos to piro.)
|
||||
|
||||
What's new in psycopg 2.0 beta 6
|
||||
|
|
|
@ -20,9 +20,12 @@ Connection and cursor factories
|
|||
|
||||
psycopg 2 exposes two new-style classes that can be sub-classed and expanded to
|
||||
adapt them to the needs of the programmer: `cursor` and `connection`. The
|
||||
`connection` class is usually sub-classed only to provide a . `cursor` is much
|
||||
more interesting, because it is the class where query building, execution and
|
||||
result type-casting into Python variables happens.
|
||||
`connection` class is usually sub-classed only to provide an easy way to create
|
||||
customized cursors but other uses are possible. `cursor` is much more
|
||||
interesting, because it is the class where query building, execution and result
|
||||
type-casting into Python variables happens.
|
||||
|
||||
`connection` instances
|
||||
|
||||
Row factories
|
||||
-------------
|
||||
|
@ -133,6 +136,7 @@ The above function call results in the SQL command::
|
|||
|
||||
INSERT INTO atable (apoint) VALUES ((1.23, 4.56));
|
||||
|
||||
|
||||
.. _PEP-246: http://www.python.org/peps/pep-0246.html
|
||||
|
||||
|
||||
|
|
|
@ -300,6 +300,7 @@ connection_dealloc(PyObject* obj)
|
|||
|
||||
Py_XDECREF(self->notice_list);
|
||||
Py_XDECREF(self->notifies);
|
||||
Py_XDECREF(self->async_cursor);
|
||||
|
||||
pthread_mutex_destroy(&(self->lock));
|
||||
|
||||
|
|
|
@ -1,19 +1,11 @@
|
|||
import psycopg
|
||||
import psycopg.extras
|
||||
import psycopg2
|
||||
import threading, os, time, gc
|
||||
|
||||
conn = psycopg.connect('dbname=test')
|
||||
#curs = conn.cursor()
|
||||
#curs.execute("CREATE TABLE itest (n int4)")
|
||||
|
||||
#for i in xrange(10000000):
|
||||
# curs = conn.cursor()
|
||||
# curs.execute("INSERT INTO itest VALUES (1)")
|
||||
# curs.execute("SELECT '2003-12-12 10:00:00'::timestamp AS foo")
|
||||
# curs.execute("SELECT 'xxx' AS foo")
|
||||
# curs.fetchall()
|
||||
# curs.close()
|
||||
|
||||
curs = conn.cursor(factory=psycopg.extras.DictCursor)
|
||||
curs.execute("select 1 as foo")
|
||||
x = curs.fetchone()
|
||||
print x['foo']
|
||||
for i in range(20000):
|
||||
conn = psycopg2.connect('dbname=test')
|
||||
del conn
|
||||
if i%200 == 0:
|
||||
datafile = os.popen('ps -p %s -o rss' % os.getpid())
|
||||
line = datafile.readlines(2)[1].strip()
|
||||
datafile.close()
|
||||
print str(i) + '\t' + line
|
||||
|
|
42
sandbox/stress2.py
Normal file
42
sandbox/stress2.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
import psycopg2
|
||||
|
||||
import threading, os, time, gc
|
||||
|
||||
super_lock = threading.Lock()
|
||||
|
||||
def f():
|
||||
try:
|
||||
conn = psycopg2.connect('dbname=testx')
|
||||
#c = db.cursor()
|
||||
#c.close()
|
||||
#conn.close()
|
||||
del conn
|
||||
except:
|
||||
pass
|
||||
#print "ERROR"
|
||||
|
||||
def g():
|
||||
n = 30
|
||||
k = 0
|
||||
i = 1
|
||||
while i > 0:
|
||||
while n > 0:
|
||||
threading.Thread(target=f).start()
|
||||
time.sleep(0.001)
|
||||
threading.Thread(target=f).start()
|
||||
time.sleep(0.001)
|
||||
threading.Thread(target=f).start()
|
||||
n -= 1
|
||||
while threading.activeCount() > 1:
|
||||
time.sleep(0.01)
|
||||
datafile = os.popen('ps -p %s -o rss' % os.getpid())
|
||||
line = datafile.readlines(2)[1].strip()
|
||||
datafile.close()
|
||||
n = 30
|
||||
print str(k*n) + '\t' + line
|
||||
k += 1
|
||||
|
||||
while threading.activeCount()>1:
|
||||
pass
|
||||
|
||||
g()
|
9
sandbox/tzhalf.py
Normal file
9
sandbox/tzhalf.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
import datetime
|
||||
import time
|
||||
import psycopg2
|
||||
|
||||
conn = psycopg2.connect("dbname=test")
|
||||
curs = conn.cursor()
|
||||
curs.execute("set timezone = 'Asia/Calcutta'")
|
||||
curs.execute("SELECT now()")
|
||||
print curs.fetchone()[0]
|
Loading…
Reference in New Issue
Block a user