472,374 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Importing modules in embedded Python

Hello everyone,

I can embed Python interpreter in C code now, but now there's another
problem, importing modules in Python code doesn't work:

Exception exceptions.ImportError:
'/usr/lib/python2.4/lib-dynload/timemodule.so: undefined symbol:
PyModule_AddObject' in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
Aborted

The (autogenerated) C code:
---cut---
#include <Python.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>
#include <signal.h>

void userbreak(int sig)
{
Py_Finalize();
printf("Interrupted..\n");
exit(sig);
}

void terminaterun(int sig)
{
Py_Finalize();
printf("Received SIGTERM. Terminating.\n");
exit(sig);
}

int main(int argc, char **argv)
{
Py_Initialize();
PyObject *pyCode, *mainmodule, *maindict;
mainmodule = PyImport_AddModule("__main__");
maindict = PyModule_GetDict(mainmodule);
unsigned int size = 272;

unsigned char python_code[] = { 0x63,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x40,0x00,0x00,0x00,0x73,0x16,0x00,0x00,0x00,0x64,
0x00,0x00,0x6B,0x00,0x00,0x5A,0x00,0x00,0x64,0x01,
0x00,0x84,0x00,0x00,0x5A,0x01,0x00,0x64,0x00,0x00,
0x53,0x28,0x02,0x00,0x00,0x00,0x4E,0x63,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x43,0x00,0x00,0x00,0x73,0x23,0x00,0x00,0x00,0x74,
0x00,0x00,0x69,0x01,0x00,0x64,0x01,0x00,0x83,0x01,
0x00,0x01,0x64,0x02,0x00,0x47,0x48,0x74,0x00,0x00,
0x69,0x01,0x00,0x64,0x03,0x00,0x83,0x01,0x00,0x01,
0x64,0x00,0x00,0x53,0x28,0x04,0x00,0x00,0x00,0x4E,
0x69,0x01,0x00,0x00,0x00,0x74,0x07,0x00,0x00,0x00,
0x73,0x75,0x63,0x63,0x65,0x73,0x73,0x69,0x5A,0x00,
0x00,0x00,0x28,0x02,0x00,0x00,0x00,0x74,0x04,0x00,
0x00,0x00,0x74,0x69,0x6D,0x65,0x74,0x05,0x00,0x00,
0x00,0x73,0x6C,0x65,0x65,0x70,0x28,0x00,0x00,0x00,
0x00,0x28,0x00,0x00,0x00,0x00,0x28,0x00,0x00,0x00,
0x00,0x74,0x07,0x00,0x00,0x00,0x74,0x65,0x73,0x74,
0x2E,0x70,0x79,0x74,0x04,0x00,0x00,0x00,0x74,0x65,
0x73,0x74,0x04,0x00,0x00,0x00,0x73,0x06,0x00,0x00,
0x00,0x00,0x01,0x0D,0x01,0x05,0x01,0x28,0x02,0x00,
0x00,0x00,0x52,0x01,0x00,0x00,0x00,0x52,0x04,0x00,
0x00,0x00,0x28,0x02,0x00,0x00,0x00,0x52,0x04,0x00,
0x00,0x00,0x52,0x01,0x00,0x00,0x00,0x28,0x00,0x00,
0x00,0x00,0x28,0x00,0x00,0x00,0x00,0x52,0x03,0x00,
0x00,0x00,0x74,0x01,0x00,0x00,0x00,0x3F,0x02,0x00,
0x00,0x00,0x73,0x02,0x00,0x00,0x00,0x09,0x02 };

pyCode = PyMarshal_ReadObjectFromString((PyObject *)
python_code, size);

(void) signal(SIGINT, userbreak);
(void) signal(SIGTERM, terminaterun);
PyEval_EvalCode(pyCode, maindict, maindict);

Py_Finalize();

}
---cut---

The Python code:

import time

def test():
time.sleep(1)
print "success"
time.sleep(90)
How do I manage to get modules imported? Anybody?

Jul 2 '08 #1
0 837

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

Similar topics

2
by: Vsevolod (Simon) Ilyushchenko | last post by:
Hi, Last year I have written a Perl module to serve as a backend to Macromedia Flash applications: http://www.simonf.com/amfperl I have just rewritten it in Python, which I have not used...
3
by: stefan | last post by:
Hi Folks, I currenty extended some of my C++ functionality to python and also embedded python to use python functionality in my C++ system (and use as well these extended functions). While...
0
by: Mark English | last post by:
Basic problem: If there is a C-extension module in a package and it tries to import another python module in the same package without using the fully qualified path, the import fails. Config:...
0
by: Brandon Metcalf | last post by:
I come from a Perl and C background and have been given an application written in Python to maintain and I know very little about Python. I'm having trouble at run time with importing modules. ...
6
by: Kamilche | last post by:
I have a large project that is getting complex, and I would like to print the docstrings without importing the modules. The only Python utility I could find references is apparently defunct and...
0
by: Jure Vrscaj | last post by:
Hi, as title implies, I wrote a simple module that allows importing modules or even packages via http, conceptually similar to zipimport (of which I learned about during the process of writing...
0
Bulldog
by: Bulldog | last post by:
I have been playing around with this issue for a while and seen some previous posting trying to address the problem but I haven't seen any answers to the problem so I am reposting it in my quest for...
0
by: Martin P. Hellwig | last post by:
Hello all, I had some troubles in the past how to arrange my packages and modules, because I usually don't develop my stuff in the Lib\site-packages directory I have some troubles when importing...
7
by: Hussein B | last post by:
Hey, Suppose I have a Python application consists of many modules (lets say it is a Django application). If all the modules files are importing sys module, how many times the sys module will be...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.