473,721 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

shelve: writing out updates?!

Shelve uses dbm and pickle to make a persistent object store. The
"db" in "dbm" stands for "database" and while I didn't expect full
ACID capability, I'd have thought there'd be at least some minimum
gesture towards durability of updates. But say that s is a shelve
object. If I say

s[whatever] = value

there is no way apparent from the shelve docs to get the update
flushed out to the disk file until the shelve is actually closed. If
I'm using the shelve to store stuff in a long-running server, it could
be months before the shelve closes.

Is shelve really missing this capability?

Thanks.
Jul 31 '05 #1
8 1569
Paul Rubin wrote:
Shelve uses dbm and pickle to make a persistent object store. The
"db" in "dbm" stands for "database" and while I didn't expect full
ACID capability, I'd have thought there'd be at least some minimum
gesture towards durability of updates. But say that s is a shelve
object. If I say

s[whatever] = value

there is no way apparent from the shelve docs to get the update
flushed out to the disk file until the shelve is actually closed. If
I'm using the shelve to store stuff in a long-running server, it could
be months before the shelve closes.

Is shelve really missing this capability?


No. Call the .sync() method. Unfortunately, the shelve module is not
well-documented.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 31 '05 #2
On 30 Jul 2005 17:48:39 -0700, Paul Rubin <http://ph****@NOSPAM.i nvalid> wrote:
Shelve uses dbm and pickle to make a persistent object store. The
"db" in "dbm" stands for "database" and while I didn't expect full
ACID capability,
What is ACID?
I'd have thought there'd be at least some minimum
gesture towards durability of updates. But say that s is a shelve
object. If I say

s[whatever] = value

there is no way apparent from the shelve docs to get the update
flushed out to the disk file until the shelve is actually closed.


Wierd. I'd expect something like an s.flush() function.
--
Email: zen19725 at zen dot co dot uk
Jul 31 '05 #3
On Sat, 30 Jul 2005 17:57:17 -0700, Robert Kern <rk***@ucsd.edu > wrote:
Paul Rubin wrote:
Shelve uses dbm and pickle to make a persistent object store. The
"db" in "dbm" stands for "database" and while I didn't expect full
ACID capability, I'd have thought there'd be at least some minimum
gesture towards durability of updates. But say that s is a shelve
object. If I say

s[whatever] = value

there is no way apparent from the shelve docs to get the update
flushed out to the disk file until the shelve is actually closed. If
I'm using the shelve to store stuff in a long-running server, it could
be months before the shelve closes.

Is shelve really missing this capability?


No. Call the .sync() method. Unfortunately, the shelve module is not
well-documented.


Obviously it's good when stuff is well documented.

I wonder if the barrier to good documentation is set too high?
If i wanted to add some documentation here, I'd have to download the
current source for the latest Python documentation, download,
install and learn the code that processes the source documentation,
write my changes then send the results into the CVS. (I'm assuming
that's roughly correct -- I haven't actually done it).

The point is, that would be a major effort, too major to merely add
a few lines detailing the .sync method.

But, what if the Python documentation was on a Wiki? Then it would
be easy to update! Of course, we would have to guard against false
or malicious updates, but Wikipedia manage that OK. The
Documentation Wiki could then be used as a basis for the "official"
documentation that comes with each new release.

Does this idea make some sense? Or are there hidden pitfalls?

--
Email: zen19725 at zen dot co dot uk
Jul 31 '05 #4
phil hunt wrote:
Obviously it's good when stuff is well documented.

I wonder if the barrier to good documentation is set too high?
If i wanted to add some documentation here, I'd have to download the
current source for the latest Python documentation, download,
install and learn the code that processes the source documentation,
write my changes then send the results into the CVS. (I'm assuming
that's roughly correct -- I haven't actually done it).
No, write the content in a reasonable format (i.e. plain text), post it
to the bug tracker, assign it to Fred Drake (I think), and he'll put it
in the right format. If it's longer documentation, like for a full
module, then it's better to actually learn the LaTeX so it can be
dropped in as is.
The point is, that would be a major effort, too major to merely add
a few lines detailing the .sync method.

But, what if the Python documentation was on a Wiki? Then it would
be easy to update! Of course, we would have to guard against false
or malicious updates, but Wikipedia manage that OK.
That's a debatable assertion, but I don't think we'll have the same
problems of Wikipedia thanks to the apolitical nature of Python
documentation.
The
Documentation Wiki could then be used as a basis for the "official"
documentation that comes with each new release.

Does this idea make some sense? Or are there hidden pitfalls?


Yes! Someone actually has to do it! The same idea has come up time and
time again. It's still not here because no one has been able to commit
to the effort involved.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 31 '05 #5
ze******@zen.co .uk (phil hunt) writes:
No. Call the .sync() method. Unfortunately, the shelve module is not
well-documented.


Obviously it's good when stuff is well documented.

I wonder if the barrier to good documentation is set too high?
If i wanted to add some documentation here, ...


I entered a sourceforge bug asking that the doc be updated (thanks,
Robert!). I've done that several times before for similar small doc
bugs and they've always been taken care of reasonably quickly.
There's a "documentat ion" category in the bug reporting template for
this purpose.
Jul 31 '05 #6
ze******@zen.co .uk (phil hunt) writes:
What is ACID?
Basically it means full-blown a transactional database that handles
concurrent updates correctly. See:

http://en.wikipedia.org/wiki/ACID
Wierd. I'd expect something like an s.flush() function.


Thanks to Robert Kern for pointing out that the answer is s.sync().
Jul 31 '05 #7
phil hunt wrote:
But, what if the Python documentation was on a Wiki? Then it would
be easy to update! Of course, we would have to guard against false
or malicious updates, but Wikipedia manage that OK. The
Documentation Wiki could then be used as a basis for the "official"
documentation that comes with each new release.

Does this idea make some sense? Or are there hidden pitfalls?


I thought the `Annotatable Python Docs`_ were a good idea but they seem
to have fallen into disuse.

... _Annotatable Python Docs: http://pydoc.amk.ca/frame.html
--
Michael Hoffman
Jul 31 '05 #8
Robert Kern <rk***@ucsd.edu > writes:
The Documentation Wiki could then be used as a basis for the
"official" documentation that comes with each new release.
Does this idea make some sense? Or are there hidden pitfalls?


Yes! Someone actually has to do it!


I think someone is working on this as part of the summer of code
program (but am not sure about that...).

Cheers,
mwh

--
QNX... the OS that walks like a duck, quacks like a duck, but is,
in fact, a platypus. ... the adventures of porting duck software
to the platypus were avoidable this time. -- Chris Klein, asr
Jul 31 '05 #9

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

Similar topics

6
4752
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 windows ME on a P-4 1.4 GHz, however, it keeps crashing on reading from the shelved file the second...
2
1451
by: AK | last post by:
Hello, I'm using shelve module in python 2.3 and I found that it does a very odd thing, at least very unexpected to me. It seems that the data of a replaced or deleted key stays in filename.dat file. Example: >>> d = *1000 >>> from shelve import *
0
2466
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 importantdiscoveries: 1. Attributes defined in __init__ after an error is raised will not be apart of the...
0
1120
by: Blair Hall | last post by:
I am having trouble understanding the correct use of 'shelve'. I have a number of small programs that read and write to a single shelve file (not multithreading though). It seems that by writing to an existing entry I sometimes corrupt the database. For instance, I get the problem when a Python script has opened the file and read and written a few objects it then tries to overwrite an existing entry:
0
1065
by: Nicholas Wieland | last post by:
I'm using the shelve module for a program I'm writing, and reading the source I've noted that shelve doesn't use new style classes. Well, this is the first time I use *seriously* new style classes (I work primarly on Zope and Python 2.1), so the result is probably far from production code, but after half an hour of hacking my Shelf class seems to work like the original one (much more than what I expected...) :) class Shelf (dict): def...
0
1090
by: Michele Simionato | last post by:
The standard library says: """ The shelve module does not support concurrent read/write access to shelved objects. (Multiple simultaneous read accesses are safe.) When a program has a shelf open for writing, no other program should have it open for reading or writing. """ But what about threads? If a single program open a shelve and many threads
3
7864
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")
5
1645
by: gluckj | last post by:
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...
1
2054
by: bluesmanu | last post by:
Hi all, I am trying to use the shelve module to save an object of a 'Electron' class I made into a file. The writing goes well but the reading goes : Traceback (most recent call last): File "<stdin>", line 1, in <module> File "shelve.py", line 113, in __getitem__ value = Unpickler(f).load() AttributeError: 'module' object has no attribute 'Electron'
0
8858
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6678
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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
2
2596
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2146
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.