ply and threads

dean deank at yahoo.com
Thu May 7 08:25:55 EDT 2009


I have two threads that exchange information by passing messages. I wanted
to parse those messages with ply. I'd prefer using two independent parsers
so that I can avoid using locks.

Can somebody explain how to do this with ply? Ply seems to be doing a lot
of odd things, such as reading the the python file that imported it,
reading doc strings of it's functions, etc, so I'm not sure how to make
this thread safe. This is from yacc.py:

# The current implementation is only somewhat object-oriented. The
# LR parser itself is defined in terms of an object (which allows multiple
# parsers to co-exist).  However, most of the variables used during table
# construction are defined in terms of global variables.  Users shouldn't
# notice unless they are trying to define multiple parsers at the same
# time using threads (in which case they should have their head examined).

It would seem that creating two parsers in the main thread, and then
passing one of them to the other thread, is all I need to do to be thread
safe?

But then again I'm not even sure how to create two parsers. Examples I've
seen just call yacc.yacc() at the end, and do not even access yacc
instances.

Any help is appreciated and thanks in advance.

Dean



More information about the Python-list mailing list