473,396 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Jul 19 '05 #1
0 1293

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
1
by: Justin Johnson | last post by:
Hello, I'm trying to build Python 2.5.0 on AIX 5.3 using IBM's compiler (VisualAge C++ Professional / C for AIX Compiler, Version 6). I run configure and make, but makes fails with undefined...
0
by: mg | last post by:
When make gets to the _ctypes section, I am getting the following in my output: building '_ctypes' extension creating build/temp.solaris-2.10-i86pc-2.5/home/ecuser/Python-2.5.1/ Modules/_ctypes...
30
by: Ivan Reborin | last post by:
Hello everyone, I was wondering if anyone here has a moment of time to help me with 2 things that have been bugging me. 1. Multi dimensional arrays - how do you load them in python For...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.