Issue233

Title The "inspect" module does not work after loading a compiled module
Priority bug Status resolved
Superseder Nosy List kayhayen, saslanbeigi
Assigned To kayhayen Keywords wrong_execution

Created on 2015-08-19.01:46:20 by saslanbeigi, last changed by kayhayen.

Messages
msg1480 (view) Author: kayhayen Date: 2015-08-27.04:30:37
Part of 0.5.14 release.
msg1461 (view) Author: saslanbeigi Date: 2015-08-22.13:57:04
It does work, indeed! Thanks a lot Kay.
msg1460 (view) Author: kayhayen Date: 2015-08-22.11:33:25
I just pushed stuff to factory that fixes the issue. I believe loading a compiled 
module broke the compiled executable isinstance checks too, so that's a larger 
improvement than I thought, and actually a bug fix.
msg1450 (view) Author: saslanbeigi Date: 2015-08-20.19:13:08
Awesome, thanks! Please keep me updated.
msg1440 (view) Author: kayhayen Date: 2015-08-19.14:38:54
Hello,

for module compilation, the inspect module is not patched. I am going to check 
out, if an alternative route, registering with the "abc" module, won't be a 
better idea anyway, or if compile modules, when loaded, should do the same as 
binaries do, which could cause other issues I guess.

I agree that should work for you, and will make it work.

The real solution is of course to not compile long.

Yours,
Kay
msg1439 (view) Author: saslanbeigi Date: 2015-08-19.01:46:20
Hi Kay,
(I don't know if what I am reporting here is a bug or a feature.)

Consider the following:
class_info/
    __init__.py
    args.py
main/
    main.py

where 
args.py
-----------------------------------------------------------
import inspect

def constructor_args(class_):
	return inspect.getargspec(class_.__init__).args[:]
-----------------------------------------------------------

and

main.py
-----------------------------------------------------------
from class_info.args import constructor_args

class Person:
	def __init__(self, name):
		self.name = name

print(constructor_args(Person))
-----------------------------------------------------------

Say we create an extension module executable as follows:
$ nuitka --recurse-all --module class_info --recurse-directory=class_info

Also, in main/ we execute
$ nuitka --standalone main.py

Of course, at this point, main.py knows nothing about class_info.py. If I then move 
class_info.so into main/main.dist/ and execute ./main/main.dist/main.exe, I get the 
following error:

  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", 
line 816, in getargspec
    raise TypeError('{!r} is not a Python function'.format(func))
TypeError: <unbound compiled_method Person.__init__> is not a Python function

If I put main.py and class.py in the same directory and compile main.py in standalone 
mode this problem does not happen. Is this a feature or bug?

The reason why I want to do what I described is that I have a Python module, equivalent 
of class_info in the example above, which takes very long to compile. If I have 10 
python scripts which reference this package, they would all take very long to compile 
as a result. I would like to compile (the equivalent of) class_info only once, and copy 
class_info.so into the various .dist folders. Is this the correct strategy?

Thanks,
Siavash
History
Date User Action Args
2015-08-27 04:30:37kayhayensetstatus: testing -> resolved
messages: + msg1480
2015-08-26 16:02:48jimrsetmessages: - msg1477
2015-08-26 16:02:16jimrsetmessages: + msg1477
2015-08-22 13:57:04saslanbeigisetmessages: + msg1461
2015-08-22 11:33:25kayhayensetstatus: chatting -> testing
messages: + msg1460
keyword: + wrong_execution
title: inspect module -> The "inspect" module does not work after loading a compiled module
2015-08-20 19:13:08saslanbeigisetmessages: + msg1450
2015-08-19 14:38:54kayhayensetstatus: unread -> chatting
messages: + msg1440
2015-08-19 01:46:20saslanbeigicreate