Jump to content
Sign in to follow this  
PierreC

Unable to instantiate the library twice

Recommended Posts

Hello,

 

In my quest to integrate python scripting into my application, I encounter another problem. I have to use P4D in a kind of plugin of my Windows application, which forces me to instantiate and release the python library several times in the same process (but never simultaneously). This is not a problem except when some modules are imported. For example, if I import numpy or win32com, the second call to import triggers an exception: EPyTypeError for win32com, Access violation for numpy.
Here is an ultra-simplified example of what I do:

program LoadTwice;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  PythonEngine;

var
  pythonEngine: TPythonEngine;

begin
  pythonEngine:= TPyThonEngine.Create(nil);
  pythonEngine.LoadDll;
  pythonEngine.ExecString('import numpy');
  pythonEngine.Free;

  pythonEngine:= TPyThonEngine.Create(nil);
  pythonEngine.LoadDll;
  pythonEngine.ExecString('import numpy');
  pythonEngine.Free;
end.

Do you have any idea what I'm doing wrong?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×