From 7806fc736a2ebce304452b1a9fd595894cddfa8f Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Tue, 9 Oct 2018 00:00:12 +0200 Subject: Sandbox removed The sandbox directory was there to test issues before we had full test coverage and to try quick and dirty Python snippets before moving them to the examples directory, sending them to mailing list or copying them to the docs. Almost anything that was in sandbox is now in the examples directory or has been refactored into a full test, or is so old that is of no use anymore. So, adieu sandbox. --- sandbox/leak.test.py | 82 ---------------------------------------------------- 1 file changed, 82 deletions(-) delete mode 100644 sandbox/leak.test.py (limited to 'sandbox/leak.test.py') diff --git a/sandbox/leak.test.py b/sandbox/leak.test.py deleted file mode 100644 index bae995f..0000000 --- a/sandbox/leak.test.py +++ /dev/null @@ -1,82 +0,0 @@ -""" -script: test_leak.py - -This script attempts to repeatedly insert the same list of rows into -the database table, causing a duplicate key error to occur. It will -then roll back the transaction and try again. - -Database table schema: - -- CREATE TABLE t (foo TEXT PRIMARY KEY); - -There are two ways to run the script, which will launch one of the -two functions: - -# leak() will cause increasingly more RAM to be used by the script. -$ python leak - -# noleak() does not have the RAM usage problem. The only difference -# between it and leak() is that 'rows' is created once, before the loop. -$ python noleak - -Use Control-C to quit the script. -""" -import sys -import psycopg2 - -DB_NAME = 'test' - -connection = psycopg2.connect(database=DB_NAME) -cursor = connection.cursor() -# Uncomment the following if table 't' does not exist -create_table = """CREATE TABLE t (foo TEXT PRIMARY KEY)""" -cursor.execute(create_table) - -insert = """INSERT INTO t VALUES (%(foo)s)""" - -def leak(): - """rows created in each loop run""" - count = 0 - while 1: - try: - rows = [] - for i in range(1, 100): - row = {'foo': i} - rows.append(row) - count += 1 - print("loop count:", count) - cursor.executemany(insert, rows) - connection.commit() - except psycopg2.IntegrityError: - connection.rollback() - -def noleak(): - """rows created once, before the loop""" - rows = [] - for i in range(1, 100): - row = {'foo': i} - rows.append(row) - count = 0 - while 1: - try: - count += 1 - print("loop count:", count) - cursor.executemany(insert, rows) - connection.commit() - except psycopg2.IntegrityError: - connection.rollback() - -usage = "%s requires one argument: 'leak' or 'noleak'" % sys.argv[0] -try: - if 'leak' == sys.argv[1]: - run_function = leak - elif 'noleak' == sys.argv[1]: - run_function = noleak - else: - print(usage) - sys.exit() -except IndexError: - print(usage) - sys.exit() - -# Run leak() or noleak(), whichever was indicated on the command line -run_function() -- cgit v1.2.1