Last Updated: February 25, 2016·
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.
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
HTTP Posts in Ruby
Have a fresh tip? Share with Coderwall community!
Post a tip
Best #Ruby Authors
Sponsored by #native_company# — Learn More