Skip to content

Commit

Permalink
Bugfix: sqlite3 transactions on python3.6
Browse files Browse the repository at this point in the history
- Python 3.6 switches the behavior of transaction handling (no longer
  auto-committing before schema modifying commands).  There are some
  weird bugs where it doesn't know a transaction is open and doesn't
  commit, or something like that.  Just commiting manually creates
  other errors.
- This is a workaround that works on both python3.6 and older python.
- Possibly related things, but they don't contain enough to solve it:
  ghaering/pysqlite#109
  buildbot/buildbot#2738
  • Loading branch information
rkdarst committed Feb 28, 2017
1 parent 05e88cf commit 8d05c3c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions import_gtfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,9 +1646,14 @@ def import_gtfs(gtfs_sources, output, preserve_connection=False,
cur.execute('PRAGMA page_size = 4096;')
cur.execute('PRAGMA mmap_size = 1073741824;')
cur.execute('PRAGMA cache_size = -2000000;')
# Changes of isolation level are python3.6 workarounds -
# eventually will probably be fixed and this can be removed.
conn.isolation_level = None # change to autocommit mode (former default)
cur.execute('PRAGMA journal_mode = OFF;')
#cur.execute('PRAGMA journal_mode = WAL;')
cur.execute('PRAGMA synchronous = OFF;')
conn.isolation_level = '' # change back to python default.
# end python3.6 workaround

#TableLoader.mode = 'index'
# Do the actual importing.
Expand Down Expand Up @@ -1710,7 +1715,11 @@ def import_gtfs(gtfs_sources, output, preserve_connection=False,

if print_progress:
print("Vacuuming...")
# Next 3 lines are python 3.6 work-arounds again.
conn.isolation_level = None # former default of autocommit mode
cur.execute('VACUUM;')
conn.isolation_level = '' # back to python default
# end python3.6 workaround
if print_progress:
print("Analyzing...")
cur.execute('ANALYZE')
Expand Down

0 comments on commit 8d05c3c

Please sign in to comment.