diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2013-04-07 20:11:43 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2013-04-07 22:02:52 +0100 |
commit | 61d496b2edb6946597a2dd7cd4ee105de2ea5b2b (patch) | |
tree | e8ca2e504e89d7873ed3e014e828cfa36b301992 /scripts/ticket58.py | |
parent | 04c09b7b38b9b6df9fc7f7e6d25b8955828031d1 (diff) | |
download | psycopg2-61d496b2edb6946597a2dd7cd4ee105de2ea5b2b.tar.gz |
Script to test ticket #58 moved into sandbox
We don't need it distributed in the sdist
Diffstat (limited to 'scripts/ticket58.py')
-rw-r--r-- | scripts/ticket58.py | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/scripts/ticket58.py b/scripts/ticket58.py deleted file mode 100644 index 95520c1..0000000 --- a/scripts/ticket58.py +++ /dev/null @@ -1,75 +0,0 @@ -""" -A script to reproduce the race condition described in ticket #58 - -from https://bugzilla.redhat.com/show_bug.cgi?id=711095 - -Results in the error: - - python: Modules/gcmodule.c:277: visit_decref: Assertion `gc->gc.gc_refs != 0' - failed. - -on unpatched library. -""" - -import threading -import gc -import time - -import psycopg2 -from StringIO import StringIO - -done = 0 - -class GCThread(threading.Thread): - # A thread that sits in an infinite loop, forcing the garbage collector - # to run - def run(self): - global done - while not done: - gc.collect() - time.sleep(0.1) # give the other thread a chance to run - -gc_thread = GCThread() - - -# This assumes a pre-existing db named "test", with: -# "CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);" - -conn = psycopg2.connect("dbname=test user=postgres") -cur = conn.cursor() - -# Start the other thread, running the GC regularly -gc_thread.start() - -# Now do lots of "cursor.copy_from" calls: -print "copy_from" -for i in range(1000): - f = StringIO("42\tfoo\n74\tbar\n") - cur.copy_from(f, 'test', columns=('num', 'data')) - # Assuming the other thread gets a chance to run during this call, expect a - # build of python (with assertions enabled) to bail out here with: - # python: Modules/gcmodule.c:277: visit_decref: Assertion `gc->gc.gc_refs != 0' failed. - -# Also exercise the copy_to code path -print "copy_to" -cur.execute("truncate test") -f = StringIO("42\tfoo\n74\tbar\n") -cur.copy_from(f, 'test', columns=('num', 'data')) -for i in range(1000): - f = StringIO() - cur.copy_to(f, 'test', columns=('num', 'data')) - -# And copy_expert too -print "copy_expert" -cur.execute("truncate test") -for i in range(1000): - f = StringIO("42\tfoo\n74\tbar\n") - cur.copy_expert("copy test to stdout", f) - -# Terminate the GC thread's loop: -done = 1 - -cur.close() -conn.close() - - |