← Back to team overview

yade-dev team mailing list archive

Re: Interesting python usage

 

> This is the content of my python script file:
>   from cvxopt import matrix
>   A = matrix(1, (1,4))
>   print A
> 
> In my C++ functor:
>     Py_Initialize();
>     FILE *file_1 = fopen("/home/chiab/yadeNew/Branch6/scripts/boon/cvxOpt.py","r+");
>     PyRun_SimpleFile(file_1,"/home/chiab/yadeNew/Branch6/scripts/boon/cvxOpt.py");
> 
> My simulation has only 2 particles, similar to Chiara's previous discussions.  When I type: O.step(), this appears in the console "[ 1  1  1  1]".    But when I type: O.run(2).  It hangs.  And, when I type O.run(), it fails as well.  If I include Py_Finalize();  it hangs after "O.step()".   What is happening inside YADE that stops me from doing this?

Py_Initialize will get you in trouble. Python is already initialized,
since yade itself runs in python. Don't do that.

If you want to run PyRun_SimpleFile, you need to get GIL (global
interpreter lock) first as well. Have a look what PeriodicPythonRunner
does, and read python docs on that. You're stepping on dangerous ground,
so be careful.

HTH, Vaclav




Follow ups

References