473,549 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

shelve crashing under Win ME

Hi,

I'm not a Win ME fan myself (I'm a Mac user), but I'm here in Thailand
developing software for special-needs kids, and the test PC in my home
office is a Win ME machine (sigh). So when I ported my Python program
today to the PC, it quickly crashed. Everything seems to work except
for shelve. Using the latest version of Python (2.5.1), when I do the
following in IDLE on the Win ME machine here's the result:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC
v.1310 32 bit (Intel)] on win32
IDLE 1.2.1
>>import shelve
f=shelve.open ("foo")
Traceback (most recent call last):
File "<pyshell#1 >", line 1, in <module>
f=shelve.open(" foo")
File "C:\PYTHON25\li b\shelve.py", line 225, in open
return DbfilenameShelf (filename, flag, protocol,
writeback)
File "C:\PYTHON25\li b\shelve.py", line 209, in
__init__
Shelf.__init__( self, anydbm.open(fil ename, flag),
protocol, writeback)
File "C:\PYTHON25\li b\anydbm.py", line 83, in open
return mod.open(file, flag, mode)
File "C:\PYTHON25\li b\dbhash.py", line 16, in open
return bsddb.hashopen( file, flag, mode)
File "C:\PYTHON25\li b\bsddb\__init_ _.py", line 306,
in hashopen
d.open(file, db.DB_HASH, flags, mode)
DBError: (5, 'Input/output error')
>>>
For those who know shelve, this should actually run fine (if the file
"foo" does not exist it should create it). Printing the value of "f"
should show an empty dictionary {}.

It does run fine on my iBook (under Python 2.4.4) and on my iBook's
Virtual PC running Win XP & Python 2.5.0. I do not think this is a
Python 2.5.1 problem, because my first attempt to run my program on
the Win ME machine was with a version of the program I ported using
Py2exe on the VPC under Python 2.5.0, and it crashed the same way when
run on the Win ME machine (I subsequently installed Python on the Win
ME PC to try to get to the root of the problem.)

Help! How do I get Win ME (or at least the misbehaving Win ME machine
in my office) to run shelve? (or more specifically run bsddb's
hashopen?)

Or should I trash shelve entirely and rewrite all my code to use a
simpler, homemade database scheme?

Thanks for any advice!

Warmly,
Joel
jo*******@yahoo .com

Jun 30 '07 #1
5 1639
On Saturday 30 June 2007 04:52, gl****@gmail.co m
wrote:
Hi,

I'm not a Win ME fan myself (I'm a Mac user),
but I'm here in Thailand developing software
for special-needs kids, and the test PC in my
home office is a Win ME machine (sigh). So when
I ported my Python program today to the PC, it
quickly crashed. Everything seems to work
except for shelve. Using the latest version of
Python (2.5.1), when I do the following in IDLE
on the Win ME machine here's the result:

Python 2.5.1 (r251:54863, Apr 18 2007,
08:51:08) [MSC v.1310 32 bit (Intel)] on win32
IDLE 1.2.1
>import shelve
f=shelve.open( "foo")

Traceback (most recent call last):
File "<pyshell#1 >", line 1, in <module>
f=shelve.open(" foo")
File "C:\PYTHON25\li b\shelve.py", line 225,
in open return DbfilenameShelf (filename, flag,
protocol, writeback)
File "C:\PYTHON25\li b\shelve.py", line 209,
in __init__
Shelf.__init__( self, anydbm.open(fil ename,
flag), protocol, writeback)
File "C:\PYTHON25\li b\anydbm.py", line 83, in
open return mod.open(file, flag, mode)
File "C:\PYTHON25\li b\dbhash.py", line 16, in
open return bsddb.hashopen( file, flag, mode)
File "C:\PYTHON25\li b\bsddb\__init_ _.py", line
306, in hashopen
d.open(file, db.DB_HASH, flags, mode)
DBError: (5, 'Input/output error')
For those who know shelve, this should actually
run fine (if the file "foo" does not exist it
should create it). Printing the value of "f"
should show an empty dictionary {}.

It does run fine on my iBook (under Python
2.4.4) and on my iBook's Virtual PC running Win
XP & Python 2.5.0. I do not think this is a
Python 2.5.1 problem, because my first attempt
to run my program on the Win ME machine was
with a version of the program I ported using
Py2exe on the VPC under Python 2.5.0, and it
crashed the same way when run on the Win ME
machine (I subsequently installed Python on the
Win ME PC to try to get to the root of the
problem.)

Help! How do I get Win ME (or at least the
misbehaving Win ME machine in my office) to run
shelve? (or more specifically run bsddb's
hashopen?)

Or should I trash shelve entirely and rewrite
all my code to use a simpler, homemade database
scheme?

Thanks for any advice!

Warmly,
Joel
jo*******@yahoo .com
what version of py2exe are you using?

I had a similar problem with an old version of
py2exe but it it is fixed now. If my memory is
correct I had to import dbhash into my setup for
py2exe back then to fix it..

Your code for shelve is correct, the problem is
someplace else.
jim-on-linux
http:\\www.inqvista.com




Jun 30 '07 #2
On Saturday 30 June 2007 10:07, jim-on-linux
wrote:
On Saturday 30 June 2007 04:52,
gl****@gmail.co m

wrote:
Hi,

I'm not a Win ME fan myself (I'm a Mac user),
but I'm here in Thailand developing software
for special-needs kids, and the test PC in my
home office is a Win ME machine (sigh). So
when I ported my Python program today to the
PC, it quickly crashed. Everything seems to
work except for shelve. Using the latest
version of Python (2.5.1), when I do the
following in IDLE on the Win ME machine
here's the result:

Python 2.5.1 (r251:54863, Apr 18 2007,
08:51:08) [MSC v.1310 32 bit (Intel)] on
win32 IDLE 1.2.1
>>import shelve
>>f=shelve.open ("foo")
Traceback (most recent call last):
File "<pyshell#1 >", line 1, in <module>
f=shelve.open(" foo")
File "C:\PYTHON25\li b\shelve.py", line 225,
in open return DbfilenameShelf (filename,
flag, protocol, writeback)
File "C:\PYTHON25\li b\shelve.py", line 209,
in __init__
Shelf.__init__( self,
anydbm.open(fil ename, flag), protocol,
writeback)
File "C:\PYTHON25\li b\anydbm.py", line 83,
in open return mod.open(file, flag, mode)
File "C:\PYTHON25\li b\dbhash.py", line 16, in
open return bsddb.hashopen( file, flag, mode)
File "C:\PYTHON25\li b\bsddb\__init_ _.py",
line 306, in hashopen
d.open(file, db.DB_HASH, flags, mode)
DBError: (5, 'Input/output error')
For those who know shelve, this should
actually run fine (if the file "foo" does not
exist it should create it). Printing the
value of "f" should show an empty dictionary
{}.

It does run fine on my iBook (under Python
2.4.4) and on my iBook's Virtual PC running
Win XP & Python 2.5.0. I do not think this is
a Python 2.5.1 problem, because my first
attempt to run my program on the Win ME
machine was with a version of the program I
ported using Py2exe on the VPC under Python
2.5.0, and it crashed the same way when run
on the Win ME machine (I subsequently
installed Python on the Win ME PC to try to
get to the root of the problem.)

Help! How do I get Win ME (or at least the
misbehaving Win ME machine in my office) to
run shelve? (or more specifically run bsddb's
hashopen?)

Or should I trash shelve entirely and rewrite
all my code to use a simpler, homemade
database scheme?

Thanks for any advice!

Warmly,
Joel
jo*******@yahoo .com

what version of py2exe are you using?

I had a similar problem with an old version of
py2exe but it it is fixed now. If my memory is
correct I had to import dbhash into my setup
for py2exe back then to fix it..

Your code for shelve is correct, the problem is
someplace else.
jim-on-linux
http:\\www.inqvista.com

Correction:

I had to import dbhash into my program to make
things work.

jim-on-linux
http:\\www.inqvista.com


Jun 30 '07 #3
Hi Jim,

Thanks for your messages -- however, py2exe is NOT the issue -- as you
can see with my example above, shelve is crashing even just by calling
it from IDLE (latest PC version of IDLE & Python), running on a Win ME
machine.

Anyone else out there having access to a Win ME PC willing to try it?
Thanks for checking!

In the meantime, I may replace shelve with a simpler workaround using
cPickle & basic flat file operations.

-- Joel
p.s. -- Jim, I too had to import dbhash in my program to make it work
using py2exe, so you are right on, there.

Jul 1 '07 #4
OK, here's my workaround for shelve -- it's primitive and obviously
much slower (it saves the entire dictionary each time), and you have
to manually save -- BUT: it works...even on the Win ME machine. And
it's possibly more universally portable in the long run than
shelve...Also, once you open the dictionary, it is just as fast
(perhaps faster?) than shelve for reading the contents (just not for
saving...)
--Joel

=============== =

#! /usr/local/bin/python
"""
myshelve.py -- a simpler (safer though slower) approach to shelve
"""

#Import Modules
import os, cPickle

def msopen(path):
""" open file containing pickled dict & return dict; if no such file,
create it & return empty dict """
if os.access(path, os.R_OK):
f=open(path, "r")
mydict=cPickle. load(f)
f.close()
return(mydict)
else:
f=open(path, "w")
cPickle.dump({} , f)
f.close()
return({})

def mssave(mydict,p ath):
""" pickle and save the dict to the file, overwriting previous
contents """
f=open(path, "w")
cPickle.dump(my dict, f)
f.close()

def mstest():
f1="_myshelvete st_.txt"
print "Testing myshelve..."
print "1) New file:",f1
if os.access(f1, os.F_OK): os.remove(f1)
d1=msopen(f1)
print "Contents of new file:",d1
d2=msopen(f1)
print "Contents on re-read:",d2
print "2) Write/Read/Overwrite/Read..."
d1={1:"hello",2 :"there",3:"fol ks"}
print "Test dict:",d1
mssave(d1,f1)
d2=msopen(f1)
print "Loaded:",d 2
print "Equal?",d1 ==d2
d1={1:"goodbye" ,2:"now",3:"fol ks"}
print "Test dict:",d1
mssave(d1,f1)
d2=msopen(f1)
print "Loaded:",d 2
print "Equal?",d1 ==d2
print "** DONE **"
os.remove(f1)

if __name__=="__ma in__": mstest()

Jul 1 '07 #5
gl****@gmail.co m schrieb:
OK, here's my workaround for shelve -- it's primitive and obviously
much slower (it saves the entire dictionary each time), and you have
to manually save -- BUT: it works...even on the Win ME machine. And
it's possibly more universally portable in the long run than
shelve...Also, once you open the dictionary, it is just as fast
(perhaps faster?) than shelve for reading the contents (just not for
saving...)
Notice that you don't need to use bsddb for shelve. Instead, you might
use dumbdbm instead, passing the dbm directly to shelve.Shelf. It's
probably slower than bsddb, however, updating a single key should be
faster than pickling an entire dictionary.

Regards,
Martin
Jul 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4727
by: Rami A. Kishek | last post by:
Hi - this mysterious behavior with shelve is just about to kill me. I hope someone here can shed some light. First of all, I have this piece of code which uses shelve to save instances of some class I define. It works perfectly on an old machine (PII-400) running Python 2.2.1 under RedHat Linux 8.0. When I try to run it under Python for...
0
2455
by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem stemmed from a class that raised an error inside __init__and defined a __del__ method to clean up resources. I then discovered asimilar problem in the shelve module. This led me to two...
3
7755
by: Michele Petrazzo | last post by:
Hi, I'm trying a script on a debian 3.1 that has problems on shelve library. The same script work well on a fedora 2 and I don't know why it create this problem on debian: #extract from my code import shelve class XX: def __init__(self): self._data = shelve.open("/tmp/myfile")
13
6470
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7715
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7469
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.