On Friday, January 8, 2016 at 5:18:56 PM UTC+1, Rickard Englund wrote: > First, some system info > * Windows 7 (also tested on 8 and 10) > * Python 3.5.1 64bit (previously also tested using several 3.x versions) > (also tested with 32 bit, but with 3.4.2) > * Microsoft Visual Studio 2015 (earlier version of python also tested with > Visual Studio 2013) > > We have tested with both the debug and release libs for 3.5 and 3.5.1 (those > available from python installer) with the same problem. > > The following problem has also been tested on Unix and on MacOS where it > works as expected, the problem is only in Windows. > > > Problem description: > We have an application for scientific visualization in which we have enabled > scripting using embedded python. We have exposed quite some features of our > application to python using modules, this works perfectly fine. > The problem we have is that the application crashes as soon as a script is > trying to import some of python's default libraries, such as os or random. > For example, running the single line code "import os" produces a crash with > the following stacktrace: > http://pastebin.com/QpfGrMY0 > > We initialize the python interpreter using the following: > http://pastebin.com/uyx6gdMb > > We have tried with and without the Py_NoSiteFlag = 1. When removing that flag > it works for some modules, for example "import os" works, but other modules, > for example "import random" crashes. > > > In the pastebin link above for the python initialization there are three > lines commented out, "importModule("os")","importModule("glog")" and > "importModule("random")", if I uncomment those lines the application will not > crash when importing those modules. But that is not a viable solution, we > can't import all possible modules that way. > > The following piece of code is how we execute python code: > http://pastebin.com/HDUR2LKT > > > It only crashes for modules that exists , if I try to import a module that > does not at all exist (eg import unexisting_module) , it fails as expected > with a nice error message saying it does not exist. > > > I don't know if we are doing anything wrong in the initialization of the > interpreter or when running the script. We can run scripts that are not using > any modules or are only using the python modules we create in c++ to expose > functionality of our application. > Everything is working fine on MacOSX and Linux (tested with Ubuntu) which are > the platforms we support. We had a similar setup before using python 2.x > instead of 3.x which also worked without any problems. > > > The software i am talking about is using QT for gui and and OpenGL for > hardware accelerated graphics. But I have tested it in a minimal application > where all QT stuff were omitted and the same issue is still there. > > The software is open source and can be downloaded/clones from > github.com/inviwo/inviwo. > > The python initialization is done in > https://github.com/inviwo/inviwo-dev/blob/master/modules/python3/pyinviwo.cpp > and the script compiling and running is handled in > https://github.com/inviwo/inviwo-dev/blob/master/modules/python3/pythonscript.cpp > > > I have searched a lot on google and in the issue tracker for python but found > nothing that can answer my questions. So I hope that someone here can us > solve this.
I notice now that I have pasted 2 links to our private repository, which will not work. The correct links are: https://github.com/inviwo/inviwo/blob/master/modules/python3/pyinviwo.cpp https://github.com/inviwo/inviwo/blob/master/modules/python3/pythonscript.cpp -- https://mail.python.org/mailman/listinfo/python-list