Using an alternative Python Bridge controller process

The default controller of the Python process, PBPharoPipenvProcess LanguageLinkAbstractProcess subclass: #PBPharoPipenvProcess instanceVariableNames: 'process environmentVariables serverDebugger pythonMainFile' classVariableNames: '' package: 'PythonBridge-Pharo-Processes' makes use of pipenv. We also saw how skip the control step (Using an externally started, already running Python Bridge instance). Another possibility is to use an alternative controller, namely the simpler PBPharoDirectPythonProcess LanguageLinkAbstractProcess subclass: #PBPharoDirectPythonProcess instanceVariableNames: 'process' classVariableNames: '' package: 'PythonBridge-Pharo-Processes' .

Warning This is a technical and experimental approach not needed for normal usage. It might be instructive to learn more about the internals.

Like in the previous section we start by reconfiguring the infrastructure.

PBPlatform current processStrategy: PBPharoDirectPythonProcess
  

Note that the setup which happens automatically when starting in the normal way needs to have run before !

Now create a new instance and start it.

myPythonBridge := PBApplication new
  
myPythonBridge debugMode: true
  
myPythonBridge start
  

FInally see if it works,

myPythonBridge newCommandStringFactory
	script: 'import sys';
	resultExpression: 'sys.version';
	sendAndWait
  
myPythonBridge newCommandFactory
	<< #sys asP3GI import;
	<< (#sys asP3GI => #version);
	sendAndWait
  

The implementation of PBPharoDirectPythonProcess LanguageLinkAbstractProcess subclass: #PBPharoDirectPythonProcess instanceVariableNames: 'process' classVariableNames: '' package: 'PythonBridge-Pharo-Processes' is small and readable.

Don't forget to reset like before.