Re: Frustrating segfaults with Shelf

2010-09-13 Thread Edward Grefenstette
Dear Emile,

Thank you for your response. Upgrading python and starting with a
blank database somehow did the trick!

Best,
Edward

On Sep 13, 7:09 pm, Emile van Sebille  wrote:
> On 9/13/2010 10:05 AM Edward Grefenstette said...
>
> > Dear Pythonistas,
>
> > Below is a simple script that reads relations from a generator
> > (they're just tuples of strings) and attempts to write them to a
> > database. It's simple as hell,
>
> Ecept of course that no one else can test it due to the dependencies.
>
> > and if I simply ignore the database and
> > have it print to stdout by replacing the line "depsDB[str(index)] =
> > rels" with "print rels" it works just fine. However every time I try
> > to run it just inexplicably segfaults. Help, anyone?
>
> There are reported problems with the backend database in pre 2.3 python
> versions.  There are also known problems with shelves being accessed by
> differing versions.
>
> So, I'd start by updating as needed, creating a new repository, then
> testing that.  Once it works, migrate the data over if needed.
>
> If it doesn't work, it'll be tough to help out if narrowing things down
> to a specific reproducible test case is difficult.  Describe the
> debugging techniques you're trying with the results you're getting, and
> we can help contribute with other things to try.
>
> HTH,
>
> Emile

-- 
http://mail.python.org/mailman/listinfo/python-list


Frustrating segfaults with Shelf

2010-09-13 Thread Edward Grefenstette
Dear Pythonistas,

Below is a simple script that reads relations from a generator
(they're just tuples of strings) and attempts to write them to a
database. It's simple as hell, and if I simply ignore the database and
have it print to stdout by replacing the line "depsDB[str(index)] =
rels" with "print rels" it works just fine. However every time I try
to run it just inexplicably segfaults. Help, anyone?

Best,
Edward



from WNvectorBuilder import relBuilder
import sys
import cPickle as pickle
import shelve

def main(argv):

## read filenames from command line arguments
depsFile = open(argv[1])
lemmaFile = open(argv[2])
depsDB = shelve.open(argv[3],"c")

## load lemma dictionary from lemma file
lemmaDict = pickle.load(lemmaFile)

## index of database entries
index = 0

## read relations from relation generator, write each relation to
database under new index
for rels in relBuilder(depsFile,lemmaDict):
index += 1
depsDB[str(index)] = rels
del rels

if __name__ == '__main__':
main(sys.argv)


-- 
http://mail.python.org/mailman/listinfo/python-list


Database problems

2010-09-06 Thread Edward Grefenstette
Dear Pythonistas,

For a project I'm working on, I need to store fairly large
dictionaries (several million keys) in some form (obviously not in
memory). The obvious course of action was to use a database of some
sort.

The operation is pretty simple, a function is handed a generator that
gives it keys and values, and it maps the keys to the values in a non-
relational database (simples!).

I wrote some code implementing this using anydbm (which used dbhash on
my system), and it worked fine for about a million entries, but then
crashed raising a DBPageNotFoundError. I did a little digging around
and couldn't figure out what was causing this or how to fix it.

I then quickly swapped anydbm for good ol' fashioned dbm which uses
gdbm, and it ran even faster a little longer, but after a million
entries or so it raised the ever-so-unhelpful "gdbm fatal: write
error".

I then threw caution to the winds and tried simply using cPickle's
dump in the hope of obtaining some data persistence, but it crashed
fairly early with a "IOError: [Errno 122] Disk quota exceeded".

Now the question is: is it something wrong with these dbms? Can they
not deal with very large sets of data? If not, is there a more optimal
tool for my needs? Or is the problem unrelated and has something to do
with my lab computer?

Best,
Edward
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble with running java using Popen

2009-06-23 Thread Edward Grefenstette
Bingo. I was running the python script in GNU script, and it wasn't
loading my bash config file properly. Have fixed it by
altering .screenrc and now the code runs fine. Would have never
guessed to look if you hadn't mentioned it, cheers!

Best,
Ed

On Jun 23, 11:29 pm, "Diez B. Roggisch"  wrote:
> Edward Grefenstette schrieb:
>
>
>
> > I have a java prog I need to run at some point during the execution of
> > a python module.
>
> > The path to the folder containing the all the relevant java stuff
> > (which runs fine from the command line) is stored in pkgpath. The
> > relevant code is this:
>
> >>>> os.chdir(pkgpath)
> >>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath
> >>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True)
> >>>> SemVectPackage.wait()
>
> > Here indexpath is the path to a particular index file (usually
> > indexpath = "./indexfolder/fileindex"), so that effectively Popen
> > should be running the equivalent of the shell command:
> > -
> > java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
> > -
> > which, again, runs fine in the terminal.
>
> > However running the program returns the following error (echoed from
> > shell, doesn't interrupt prog):
> > -
> > Exception in thread "main" java.lang.NoClassDefFoundError:
> > SemanticVectorsEvaluator
> > -
>
> > I have no idea why this isn't working. Anyone have any suggestions as
> > to how I might troubleshoot this?
>
> I'd say you got an CLASSPATH-issue here. You can add that explicitly via
> env as argument to Popen, or pass it via commandline-args.
>
> Diez

-- 
http://mail.python.org/mailman/listinfo/python-list


Trouble with running java using Popen

2009-06-23 Thread Edward Grefenstette
I have a java prog I need to run at some point during the execution of
a python module.

The path to the folder containing the all the relevant java stuff
(which runs fine from the command line) is stored in pkgpath. The
relevant code is this:

>>> os.chdir(pkgpath)
>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath
>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True)
>>> SemVectPackage.wait()

Here indexpath is the path to a particular index file (usually
indexpath = "./indexfolder/fileindex"), so that effectively Popen
should be running the equivalent of the shell command:
-
java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
-
which, again, runs fine in the terminal.

However running the program returns the following error (echoed from
shell, doesn't interrupt prog):
-
Exception in thread "main" java.lang.NoClassDefFoundError:
SemanticVectorsEvaluator
-

I have no idea why this isn't working. Anyone have any suggestions as
to how I might troubleshoot this?

Best,
Edward
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LaTeXing python programs

2009-05-20 Thread Edward Grefenstette
On May 20, 10:10 pm, John Reid  wrote:
> Alan G Isaac wrote:
> > The listings package is great and highly configurable.
> > Note that you can also input entire files of Python code
> > or pieces of them based on markers.  Really quite great.
>
> I tried listings. I believe pygments makes better formatted output (at
> least out of the box).

I'm trying to figure out how to use pygments. Are there any good usage
examples out there?

Ed
-- 
http://mail.python.org/mailman/listinfo/python-list


LaTeXing python programs

2009-05-20 Thread Edward Grefenstette
Yes, I am aware that this is more of a LaTeX question than a python
question, but I thought users here might be most likely to offer a
suitable recommendation.

I'm typing up my master's  thesis and will be including some of the
code used for my project in an appendix. The question is thus: is
there a LaTeX package out there that works well for presenting python
code?

verbatim is a bit ugly and doesn't wrap code, and while there are a
plethora of code colouring packages out there, they are not all easy
to use, so I thought I might ask what the popular options in the
community are.

Cheers,
Edward
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with Tkinter on OS X --- driving me insane!

2009-05-17 Thread Edward Grefenstette
Bingo! Updating to Python 6.2.2 did the trick (I had 6.2). I just had
to relink the /usr/bin/python to the Current directory in /Library/
Frameworks/Python.framework/Versions/ and everything worked without
deletions etc. Thanks for your help, everyone!

Best,
Edward
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with Tkinter on OS X --- driving me insane!

2009-05-17 Thread Edward Grefenstette
Thanks to Kevin and Ned for the pointers.
The question is now this. Running find tells me I have tk.h in the
following locations:
===
/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Tk.framework/
Versions/8.4/Headers/tk.h
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/tk.h
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Tk.framework/
Versions/8.4/Headers/tk.h
/Developer/SDKs/MacOSX10.5.sdk/usr/include/tk.h
/Library/Frameworks/Tk.framework/Versions/8.5/Headers/tk.h
/System/Library/Frameworks/Tk.framework/Versions/8.4/Headers/tk.h
/usr/include/tk.h
/usr/local/WordNet-3.0/include/tk/tk.h
===

This seams to entail that the Tk 8.4 framework seems to be installed
in
===
/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Tk.framework/
Versions/8.4/
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Tk.framework/
Versions/8.4/Headers/tk.h
/System/Library/Frameworks/Tk.framework/Versions/8.4/Headers/tk.h
===

Whereas Tk 8.5 is installed in:
===
/Library/Frameworks/Tk.framework/Versions/8.5/
===

Which ones should I delete? Should I remove all the other tk.h files?

Sorry if these are rather dumb questions, but I really do appreciate
the help.

Best,
Edward

On May 18, 1:09 am, Ned Deily  wrote:
> In article
> ,
>  Edward Grefenstette  wrote:
>
> > I thought of this. I uninstalled Tk from macports, but the same error
> > crops up. Evidently, Tk 8.5 remains installed somewhere else, but I
> > don't know where. How can I find out?
>
> Look in /Library/Frameworks for Tcl.framework and Tk.framework.  You can
> safely delete those if you don't need them.  But also make sure you
> update to the latest 2.6 (currently 2.6.2) python.org version; as noted,
> the original 2.6 python.org release had issues with user-installed Tcl
> and Tk frameworks.
>
> --
>  Ned Deily,
>  n...@acm.org

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with Tkinter on OS X --- driving me insane!

2009-05-17 Thread Edward Grefenstette
I thought of this. I uninstalled Tk from macports, but the same error
crops up. Evidently, Tk 8.5 remains installed somewhere else, but I
don't know where. How can I find out?

Best,
Edward

>
>
> Have you installed Tk version 8.5?
>
> If so, remove it. You might also install the latest 8.4 version.
> --
> Piet van Oostrum 
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: p...@vanoostrum.org

-- 
http://mail.python.org/mailman/listinfo/python-list


Help with Tkinter on OS X --- driving me insane!

2009-05-17 Thread Edward Grefenstette
Any attempt to do anything with Tkinter (save import) raises the
following show-stopping error:

"Traceback (most recent call last):
  File "", line 1, in 
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/lib-tk/Tkinter.py", line 1645, in __init__
self._loadtk()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/lib-tk/Tkinter.py", line 1659, in _loadtk
% (_tkinter.TK_VERSION, tk_version)
RuntimeError: tk.h version (8.4) doesn't match libtk.a version (8.5)"

As you can see, I'm running the vanilla install python on OS X 10.5.7.
Does anyone know how I can fix this? Google searches have yielded
results ranging from suggestions it has been fixed (not for me) to
recommendations that the user rebuild python against a newer version
of libtk (which I have no idea how to do).

I would greatly appreciate any assistance the community can provide on
the matter.

Best,
Edward
-- 
http://mail.python.org/mailman/listinfo/python-list