Ruby: SQLite3::BusyException: database is locked ?
I have a simple local script that needed threads, one to push things into a queue and one to pull them out and perform the actions (worker), and a Sinatra app.
Sometimes one of the threads, or the Sinatra would hang with a Ruby: SQLite3::BusyException: database is locked, because SQLite3 does not support concurrency.
I'm using ActiveRecord
. A simple trick is to add a Timeout option on the establish_connection
block of ActiveRecord
, now SQLite3 won't trow the exception right away.
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'database.sqlite3',
:host => 'localhost',
:timeout => 1000
)
Written by Rafael Oliveira
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#