← Back to team overview

yade-dev team mailing list archive

Re: Interesting python usage

 

Thanks, Vaclav for pointing GIL out to me.  Now I can run python from C.  But I have a question:

Why calling PyRun_SimpleString("print O.bodies[1].state.pos") in my yade C file works, but not calling it through a function defined in another script file:
      def printB():
           print O.bodies[1].state.pos

My syntax should be right, since I have tested it out with print 'abc'  (it worked).  How do I link yade to that python script file?


Yours,

Boon

 

----------------------------------------
> From: eudoxos@xxxxxxxx
> To: yade-dev@xxxxxxxxxxxxxxxxxxx
> Date: Thu, 1 Apr 2010 18:21:13 +0200
> Subject: Re: [Yade-dev] 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
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to : yade-dev@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~yade-dev
> More help : https://help.launchpad.net/ListHelp
 		 	   		  
_________________________________________________________________
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
https://signup.live.com/signup.aspx?id=60969


Follow ups

References