By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

Python/C API -- trouble creating objects

P: n/a
I have a multithreaded Python shell server (base on the sample code
'') 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 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
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.