<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bluehorn's Blog &#187; Python</title>
	<atom:link href="http://www.landschoff.net/blog/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.landschoff.net/blog</link>
	<description>Ramblings of Torsten Landschoff</description>
	<lastBuildDate>Sun, 07 Nov 2010 18:24:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to run a single unit test/unit test module with py.test</title>
		<link>http://www.landschoff.net/blog/2010/07/how-to-run-a-single-unit-testunit-test-module-with-py-test/</link>
		<comments>http://www.landschoff.net/blog/2010/07/how-to-run-a-single-unit-testunit-test-module-with-py-test/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 10:43:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[py.test]]></category>

		<guid isPermaLink="false">http://www.landschoff.net/blog/?p=203</guid>
		<description><![CDATA[Note to self: It is actually possible to select a single test module or a single test function in py.test. But passing the file name as argument to a py.test invocation selects only the doctest from that file (wtf!?). Instead, you need to call it like this: $ py.test -k test_module # to run the [...]]]></description>
			<content:encoded><![CDATA[<p>Note to self: It is actually possible to select a single test module or a single test function in <a href="http://pytest.org/">py.test</a>.</p>
<p>But passing the file name as argument to a py.test invocation selects only the doctest from that file (wtf!?). Instead, you need to call it like this:</p>
<pre lang="bash">
$ py.test -k test_module    # to run the tests from test_module.py
$ py.test -k test_func      # to run tests having the function name test_func
</pre>
<p>This is documented in the section <a href="http://codespeak.net/py/dist/test/features.html#advanced-test-selection-and-running-modes">advanced test selection and running modes</a> of the py.test documentation, although I fail to see how this is advanced.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.landschoff.net/blog/2010/07/how-to-run-a-single-unit-testunit-test-module-with-py-test/feed/</wfw:commentRss>
		<slash:comments>136</slash:comments>
		</item>
		<item>
		<title>Hitting the dynamic linker wall&#8230;</title>
		<link>http://www.landschoff.net/blog/2009/12/hitting-the-dynamic-linker-wall/</link>
		<comments>http://www.landschoff.net/blog/2009/12/hitting-the-dynamic-linker-wall/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 17:01:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[dlopen]]></category>
		<category><![CDATA[dynamic linker]]></category>

		<guid isPermaLink="false">http://www.landschoff.net/blog/?p=127</guid>
		<description><![CDATA[I was working on replacing some mockup code for testing an internal library with python. Basically, the C code is incredibly big and I would rather mock the 3rd party API we are using in python. I wrote a generator to create wrapping code that forwards the C API calls to my python module. Now [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on replacing some mockup code for testing an internal library with python. Basically, the C code is incredibly big and I would rather mock the 3rd party API we are using in python. I wrote a generator to create wrapping code that forwards the C API calls to my python module.</p>
<p>Now that most of the work is finished, I get the following error message from my python mock:</p>
<pre lang="python">
Traceback (most recent call last):
  File "simple_mockup.py", line 2, in <module>
    import threading
  File "/usr/lib/python2.5/threading.py", line 11, in <module>
    from time import time as _time, sleep as _sleep
ImportError: /usr/lib/python2.5/lib-dynload/time.so: undefined symbol: PyExc_ValueError
</pre>
<p>What&#8217;s going on here? This issue reminds me of a <a href="http://lists.debian.org/debian-gtk-gnome/1999/05/msg00095.html">bug of my ancient Debian times</a> which affected loading of GTK theme engines from python-gtk. The bug (#38138) is so old, it&#8217;s not even in the BTS archive anymore&#8230;</p>
<p>The problem is illustrated by the following example program (consisting of three files):</p>
<dl>
<dt>demo.c</dt>
<dd>
<pre lang="c">
#include <Python.h>

void test_python()
{
    Py_Initialize();
    PyRun_SimpleString("import threading\n");
}
</pre>
</dd>
<dt>main.c</dt>
<dd>
<pre lang="c">
#include <stdio.h>
#include
<dlfcn.h>

int main(void)
{
    const char *error;

    void *handle = dlopen("./demo.so", RTLD_LAZY | EXTRA_RTLD_FLAGS);
    void (*test_python)();
    *(void**) &#038;test_python = dlsym(handle, "test_python");
    if ((error = dlerror())) {
        fprintf(stderr, "%s\n", error);
        return 1;
    }

    printf("Calling test_python @ %p in shared object @ %p.\n", test_python, handle);
    (*test_python)();
    dlclose(handle);
    printf("Feels fine, finishing.\n");
    return 0;
}
</pre>
</dd>
<dt>run_it.sh</dt>
<pre lang="bash">
#! /bin/sh

gcc -shared `python-config --includes` -o demo.so demo.c `python-config --ldflags`

echo "Running example with default RTLD flags:"
gcc -DEXTRA_RTLD_FLAGS=0 -o main main.c -ldl
./main
echo

echo "Passing RTLD_GLOBAL in addition:"
gcc -DEXTRA_RTLD_FLAGS=RTLD_GLOBAL -o main main.c -ldl
./main
echo
</pre>
</dl>
<p>On my system, this results in the following output:</p>
<pre>
torsten@pulsar:~/sh_bug$ ./run_it.sh
Running example with default RTLD flags:
Calling test_python @ 0xb77084bc in shared object @ 0x96bc018.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.5/threading.py", line 11, in <module>
    from time import time as _time, sleep as _sleep
ImportError: /usr/lib/python2.5/lib-dynload/time.so: undefined symbol: PyExc_ValueError
Feels fine, finishing.

Passing RTLD_GLOBAL in addition:
Calling test_python @ 0xb783f4bc in shared object @ 0x95e1018.
Feels fine, finishing.
</pre>
<p>Sucky. So embedding Python into an application is easy but if you want to use the interpreter and its modules from a plugin, you are out of luck. Somebody knows a way around this problem? The only solution I can think of is to link libpython.so into each of the python plugins.</p>
<h3>Update: Work around</h3>
<p>Small update: For my current problem, the work around is to run the application with the python library preloaded: <tt>LD_PRELOAD=/usr/lib/libpython2.5.so.1.0 app</tt>. Back to adding functionality&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.landschoff.net/blog/2009/12/hitting-the-dynamic-linker-wall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

