Python/C API -- trouble creating objects

D

DPhelps

I have a multithreaded Python shell server (base on the sample code
'pysvr.py') that uses a C-based extension class. The trouble I'm having
is that I cannot figure out a way to create a Python object from the C
code. I'll detail the methods I've looked at and the troubles I'm
having:


Method 1)

Ideally, I could get PyRun_String to work, however I cannot figure out
how to properly get the locals and globals structures. In the examples
I've seen, people are either creating brand new globals dictionaries
and/or reusing globals as locals. The problem I have is that I
potentially have multiple threads with different globals and locals
(see pysvr.py code in Python 2.4.1 distribution). I need to reference
the locals and globals for the interpreter shell for the current
thread. PyRun_SimpleString works great, but I need to get a PyObject *
back, so I need to use PyRun_String -- so another way to phrase my
problem is:

How do I get the locals and globals used in PyRun_SimpleString for use
with PyRun_String (given that I'm in a multi-threaded,
multi-interpreter environment similar to the one found using pysvr.py).


Method 2)

PyObject_New() seems like a good possibility -- except that I have no
idea where to get a PyTypeObject* from! This is for a
Python-implemented class, e.g.: Queue.

Method 3)

Dig inside the interpreter structs (PyFrameObject, PyThreadState, etc)
and dig the locals out that way. Problem is, that's not supported, so
I'd rather not do it.


There has to be a simple way to do this simple task!!

-Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,241
Messages
2,571,223
Members
47,856
Latest member
mmorais

Latest Threads

Top