470,647 Members | 1,206 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

Python/C API -- trouble creating objects

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
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!!


Jul 19 '05 #1
0 1155

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

220 posts views Thread by Brandon J. Van Every | last post: by
10 posts views Thread by Andrew Dalke | last post: by
30 posts views Thread by Ivan Reborin | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.