bsddb version mysmatch between win32 and linux

2010-02-13 Thread Expo
Hi guys,

I found an incompatibility in the bsddb library shipped with Python
which is a different version between the win32 release and the linux
release.
This happend using Python 2.6.2 on win32 and OpenSuse 11.2.
To reproduce this problem, create a bsddb file under win32 with this
code:

import shelve

f = shelve.open( "test.bin" )
f["test"] = "test"
f.sync()
f.close()

copy test.bin in the OpenSuse system and try to open it:

import shelve

f = shelve.open( "test.bin" )
print f["test"]

and you get this traceback:

Traceback (most recent call last):
File "", line 1, in 
File "/usr/lib/python2.6/shelve.py", line 234, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/usr/lib/python2.6/shelve.py", line 218, in __init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback)
File "/usr/lib/python2.6/anydbm.py", line 83, in open
return mod.open(file, flag, mode)
File "/usr/lib/python2.6/dbhash.py", line 19, in open
return bsddb.hashopen(file, flag, mode)
File "/usr/lib/python2.6/bsddb/__init__.py", line 361, in hashopen
d.open(file, db.DB_HASH, flags, mode)
bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- ./test.bin:
unsupported hash version: 9')

I don't know yet if the problem is related to OpenSuse or to the
Python linux distribution.

How I can resolve this ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3, memory db and multithreading

2010-03-19 Thread Expo
On Mar 18, 1:58 pm, królewna  wrote:
> The problem is simple: I have multiple threads within one program. At
> least 2 threads have to have access to in-memory sqlite database. It is
> not possible to pass sqlite objects to those threads because an
> exception is rised:
>
> ProgrammingError: SQLite objects created in a thread can only be used in
> that same thread.The object was created in thread id -1219066176 and
> this is thread id -1224475792
>
> Is there any EASY way to use this in-memory db in many threads? Creating
> another connection is not a solution as it creates completely new db
> instead of connecting to the existing one.
>

You can put the SQLite database into a Singleton class and use a
semaphore to serialize the access to methods which writes to the
database.
-- 
http://mail.python.org/mailman/listinfo/python-list