473,796 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Shelve operations are very slow and create huge files

Hello Pythonistas,

I use Python shelves to store results from MySQL-Queries (using Python
for web scripting).
One script searches the MySQL-database and stores the result, the next
script reads the shelve again and processes the result. But there is a
problem: if the second script is called too early, the error "(11,
'Resource temporarily unavailable') " occurs.
So I took a closer look at the file that is generated by the shelf: The
result-list from MySQL-Query contains 14.600 rows with 7 columns. But,
the saved file is over 3 MB large and contains over 230.000 lines (!),
which seems way too much!

Following statements are used:
dbase = shelve.open(fil ename)
if dbase.has_key(k ey): #overwrite objects stored with same key
del dbase[key]
dbase[key] = object
dbase.close()

Any ideas?

Thanks,
Eric
Jul 18 '05 #1
1 3946
Eric Wichterich wrote:
Hello Pythonistas,

I use Python shelves to store results from MySQL-Queries (using Python
for web scripting).
One script searches the MySQL-database and stores the result, the next
script reads the shelve again and processes the result. But there is a
problem: if the second script is called too early, the error "(11,
'Resource temporarily unavailable') " occurs.
So I took a closer look at the file that is generated by the shelf: The
result-list from MySQL-Query contains 14.600 rows with 7 columns. But,
the saved file is over 3 MB large and contains over 230.000 lines (!),
which seems way too much!
Let's see:
3*2**20/14600/7 30.780117416829 746


Are thirty bytes per field, including administrative data, that much?
By the way, don't bother counting the lines in a file containing pickled
data; the pickle protocol inserts a newline after each attribute, unless
you specify the binary mode, e. g.:

shelve.open(fil ename, binary=True)
Following statements are used:
dbase = shelve.open(fil ename)
if dbase.has_key(k ey): #overwrite objects stored with same key
del dbase[key]
dbase[key] = object
dbase.close()
I've never used the shelve module so far, but the rule of least surprise
would suggest that

if dbase.has_key(k ey):
del dbase[key]
dbase[key] = data

is the same as

dbase[key] = data
Any ideas?


Try to omit the shelve completely, preferably by moving the second script's
operations into the first. If you want to keep two scripts, don't invoke
them independently, make a little batch file or shell script instead.

If you need an intermediate step with a preprocessed snapshot of the MySQL
table, and you have sufficient rights, use a MySQL table for the temporary
data.

Peter
Jul 18 '05 #2

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

Similar topics

6
4764
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...
1
6753
by: Kris Caselden | last post by:
Python's docs say that Shelve uses Pickle to serialize its data. However, I've noticed that Pickle can maintain internal links, while Shelve cannot. For instance: >>> d = shelve.open('shelvedata.txt',writeback=True) >>> d= >>> d=d >>> print d {'a': , 'b': } >>> d=2 >>> print d {'a': , 'b': }
0
423
by: ex laguna | last post by:
I have run into this problem below with py2exe version 0.5.0 and python 2.3.3. Does anyone know a solution or workaround for this? Thanks much! ## Begin of test.py import shelve f = shelve.open('test.txt') f = 'world' f.close()
0
1374
by: Ray O | last post by:
I have read a number of threads relating to problems with shelve, but I couldn't find one directly related my experience, so I would appreciate some advice. The closest one ended with a recommendation to upgrade to Python 2.3, but that, unfortunately, is out of my control. The system I use runs Python 2.2.2, and whichdb gives dbhash. The problem only occurs when serializing class instances; lists don't seem to be affected. Every time...
4
2340
by: Terry Hancock | last post by:
I only just recently had a look at the shelve module, and it looks pretty handy, my only question being, what if I really want two shelves? Must I use two files? Also, it seems strange that shelve only works with filenames. I would've expected there to at least be a variant that would put a shelve database on a file that is opened for read/write (that is a file object). That would be handy if, for example, I wanted to couple
3
7912
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
6520
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
1
4586
by: Matthew Schibler | last post by:
I'm a newbie to Python, with some experience using perl (where I used nested arrays and hashes extensively). I am building a script in python for a MUD I play, and I want to use the shelve module to store persistent information between script executions. The following code does not work for me, import shelve, sys, os, string db = shelve.open(os.path.abspath(os.path.dirname(sys.argv)) + '/' + 'sandbox.dat', 'c') db = 'apple'
0
1186
by: Edwin.Madari | last post by:
since choice of dbm used by shelve http://docs.python.org/lib/node327.html depends on os, and whats available on it, shevle files saved on one os, most likely do not work on another os, sometimes on similar os but different machines might not work either - goes back to what's available on that machine. inter operability of shelve files with similar os-es works! yes I had used it. For inter-operability of saved information across os-es,...
0
9535
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10242
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
10021
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
7558
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
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5453
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
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.