[Pythonmac-SIG] Re: Strange MacPython (2.2.1) Behavior

Jack Jansen Jack.Jansen@oratrix.com
Fri, 1 Nov 2002 15:16:17 +0100


JR,
my first guess is that you get two different versions of "module", 
maybe because there's one in the folder where your script lives (the 
folder where the script lives gets prepended to sys.path, but that 
doesn't happen when you run interactively.

First thing to try would be to option-run PythonInterpreter, select the 
"verbose import" option and keep the output. Then option-drag your 
scrip to the interpreter, select "verbose import" again, and compare 
the output to what you got previously.

If that all looks normal then see what happens if you import your 
script into an interactive interpreter, i.e. something like
 >>> sys.path.append("path:to:script:dir")
 >>> import _test

You can also try option-dragging your script to the interpreter and 
selecting "interactive mode after script". Then doing "import pdb; 
pdb.pm()" lets you do post-mortem debugging, and you can look at the 
value of session, try to run session_class_stor() again and seeing what 
that value is, etc.

You might also want to look closely at your C code looking at 
INCREF/DECREFs, return values (you aren't forgetting to return a value 
somewhere? That can lead to transient errors like these), etc.

On donderdag, okt 31, 2002, at 21:18 Europe/Amsterdam, JR wrote:

>> I'm running into some odd behavior from MacPython and was hoping that 
>> someone
>> (here) might be able to provide some guidance...
>
> Oops.  I hit send a tad early...
>
> Here is the complete note:
>
> I'm running into some odd behavior from MacPython (Python 2.2.1 (#134, 
> Apr
> 9 2002, 21:16:52)  [CW CARBON GUSI2 THREADS GC] on mac natively on OS X
> 10.1.5) and was hoping that someone (here) might be able to provide 
> some
> guidance...
>
> I've built a module that seemingly loads correctly, etc.  If I import 
> that
> module (e.g., from module import *) and then line by line enter Python 
> code
> in the Interpreter everything behaves fine.  Yet, the same Python code 
> read
> in from a text file (e.g., drag _test.py to PythonInterpreter) 
> exhibits what
> I can only describe as structural failures (possibly a result of 
> garbage
> collection?).  Here is some sample code:
>
> from module import *
>
> def _test():
>     session = session_class_ctor()
>     dict = session.create_dict()
>     field = dict.Get("key")
>
>
> _test()
>
> ...if I enter code like this interactively everything works fine.  
> session,
> dict and field all remain uncollected (with >0 ref counts) and exhibit 
> valid
> module defined types (i.e., type(dict) => <type 'foodict'>).  Yet, if I
> encapsulate the same code in a .py file and drag/drop it on the 
> interpreter
> the interpreter complains that instance 'dict' has no Get attribute 
> because
> it is of type None.  As in...
>
> AttributeError: 'NoneType' object has no attribute 'Get'
>
> Ideas?
> Thoughts?
>
> JR
>
>
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
>
--
- Jack Jansen        <Jack.Jansen@oratrix.com>        
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- Emma 
Goldman -