Re: plpython intermittent ImportErrors - Mailing list pgsql-general

From Stuart Bishop
Subject Re: plpython intermittent ImportErrors
Date
Msg-id CADmi=6MLei9X90gOb5xWPvOkwicWCTGqbsA=f4TBFkqseJ359A@mail.gmail.com
Whole thread Raw
In response to plpython intermittent ImportErrors  (Brian Sutherland <brian@vanguardistas.net>)
Responses Re: plpython intermittent ImportErrors  (Brian Sutherland <brian@vanguardistas.net>)
List pgsql-general
On Mon, Jan 14, 2013 at 11:30 PM, Brian Sutherland
<brian@vanguardistas.net> wrote:
> Hi,
>
> I have a plpython stored procedure which sometimes fails when I run my
> applications automated test suite. The procedure is called hundreds of
> times during the tests but only fails a few times, often with the
> following ImportError:
>
>     Traceback (most recent call last):
>       File "/Users/jinty/.buildout/eggs/setuptools-0.6c11-py2.7.egg/site.py", line 73, in <module>
>         __boot()
>       File "/Users/jinty/.buildout/eggs/setuptools-0.6c11-py2.7.egg/site.py", line 2, in __boot
>         import sys, imp, os, os.path
>       File "/Users/jinty/src/mp/lib/python2.7/os.py", line 49, in <module>
>         import posixpath as path
>       File "/Users/jinty/src/mp/lib/python2.7/posixpath.py", line 15, in <module>
>         import stat
>     ImportError: No module named stat

The first thing that pops out here is that the paths contain
references to buildout.

Can you confirm that the exception is actually being received from
PostgreSQL, or is the error coming from your test harness?

Is your plpython stored procedure supposed to be using the environment
constructed by buildout, or the system default environment?

(we use buildout for our Python code, but our plpythonu stored
procedures use the stock standard Python environment, as provided by
the Ubuntu packages).

If this is the correct environment, it sounds like you are triggering
some sort of race condition in the buildout generated .py files. You
might be able to confirm and/or work around the issue by getting your
own stanza added to the top of the generated site.py, explicitly
importing the problematic modules right at the top before any buildout
magic happens.


--
Stuart Bishop <stuart@stuartbishop.net>
http://www.stuartbishop.net/


pgsql-general by date:

Previous
From: ning chan
Date:
Subject: Streaming Replication Failover
Next
From: Sumit Raja
Date:
Subject: Re: Best method to compare subdomains