Bug in re.findall?

2008-07-04 Thread Marcin Krol
Hello everyone, Is there a bug in re.findall in Python 2.4? See: subnetlist="192.168.100.0 , 192.168.101.0" ipre=re.compile("([0-9]{1,3}\.){3}[0-9]{1,3}") >>> ipre.findall(subnetlist) ['100.', '101.'] But: a=ipre.finditer(subnetlist) >>> a.next().group() '192.168.100.0' >>> a.next().group(

Re: Bloody signal handling (in embedded Python code)

2008-07-02 Thread Marcin Krol
Right, I didn't realize before that Python interpreter has its own signal handling routines. Now I am able to handle signals in Python code, but it still barfs on exit: import time import signal import sys def userBreak(sigNum, execFrame): print "Interrupted,,," sys.exit(sigN

Bloody signal handling (in embedded Python code)

2008-07-02 Thread Marcin Krol
Hello everyone, And now for something completely different: signal handling sometimes works, sometimes it doesn't. When I embed following code, it works: count = 0 def test(): global count while True: count += 1 if (count % 10 == 0):

Re: Importing modules in embedded Python

2008-07-02 Thread Marcin Krol
OK I found the answer in yet another Google search, right after I gave up and posted here - turns out in order to import dynamically linked modules, one has to pass -E argument to the linker. Exception exceptions.ImportError: '/usr/lib/python2.4/lib-dynload/timemodule.so: undefined symbol: Py

Importing modules in embedded Python

2008-07-02 Thread Marcin Krol
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

Re: Embedding Python

2008-07-01 Thread Marcin Krol
Hello everyone, In the meantime I managed to work out another solution, mainly thanks to reading the source code of some OSS projects. I post it here so somebody else looking for solution to this problem had the example available: cut #include #include #include #include #include

Re: Embedding Python

2008-07-01 Thread Marcin Krol
Carsten Haese wrote: python_code is a C string containing the raw bytes from your pyc file. Casting that to a PyObject pointer will not magically transform it into a Python code object. well yeah, I kind of didn't think that through.. A pyc file contains the following: 1) An 8 byte head

Re: Embedding Python

2008-07-01 Thread Marcin Krol
Pau Freixes wrote: If you search this function name into Google you will can found some examples, use for example PyMarshal_ReadObjectFromString or PyMarshal_ReadObjectFromFile Rest assured I looked at a lot of code, but none of it was reading in the .pyc file. I had no idea about the 8-byte h

Embedding Python

2008-07-01 Thread Marcin Krol
Hello everyone, I'm trying to embed Python interpreter in C code, but in a specific way: loading compiled bytecode into a memory location and executing it (don't ask why, complicated reasons). PyImport_ExecCodeModule seems like obvious candidate, docs say: "Given a module name (possibly of the