Error when running leveldb with bottle LOCK: Resource temporarily unavailable

1,674 views
Skip to first unread message

dd

unread,
Jun 20, 2012, 7:51:04 AM6/20/12
to py-le...@googlegroups.com
Hello I am trying to use leveldb within the bottle web framework for python http://bottlepy.org/docs/dev/

I am using Python 3.

When I try to load a leveldb database within my bottle script I get the error:
leveldb.LevelDBError: IO error: lock ./applytomesessions/LOCK: Resource temporarily unavailable

Below is the code of my test file.

Can anyone help?

thanks

ubuntu@:~/devel$ cat temp.py
#!python3.2
import bottle
import leveldb

ldb = leveldb.LevelDB('./applytomesessions')

@bottle.route('/helloworld')
def helloworld():
    return "Hello world" 



bottle.run(reloader=True, host='localhost', port=8080)
 
ubuntu:~/devel$ python3 temp.py
Traceback (most recent call last):
  File "temp.py", line 5, in <module>
    ldb = leveldb.LevelDB('./applytomesessions')
leveldb.LevelDBError: IO error: lock ./applytomesessions/LOCK: Resource temporarily unavailable
ubuntu@:~/devel$ 

Árni Már Jónsson

unread,
Jun 23, 2012, 9:09:07 PM6/23/12
to py-le...@googlegroups.com
Hi,

I just looked at this, and it seems that the framework is forking the process, and running the startup script again. The orignal process already has the database open (hence the LOCK file), and the second process fails to open it.

import bottle, leveldb, os

print('before open %i' % os.getpid())
ldb = leveldb.LevelDB('./applytomesessions')
print('after open %i' % os.getpid())

@bottle.route('/helloworld')
def helloworld():
   return "Hello world"

bottle.run(reloader=True, host='localhost', port=8080)
outputs:

(Python-3.2.3-env)arni@laptop:~/py-leveldb-small$ python bottle_test.py 
before open 3960
after open 3960
before open 3961
Traceback (most recent call last):
  File "bottle_test.py", line 4, in <module>
    ldb = leveldb.LevelDB('./applytomesessions')
leveldb.LevelDBError: IO error: lock ./applytomesessions/LOCK: Resource temporarily unavailable


You can't use the same LevelDB database from multiple processes at the same time.

Regards, Arni
Reply all
Reply to author
Forward
0 new messages