Using an independent Python Bridge instance

Although convenient and easy to use, using the global unique Python Bridge instance (PBApplication uniqueInstance) is not the only way. In fact, you can start as many instances as you want. Step one is to create a new instance and keep a reference to it.

myPythonBridge := PBApplication new
  

This new bridge is not yet started, but we can already see that it uses its own unique network ports for communication. Next we start our new bridge.

myPythonBridge start
  

We can now use it like before, making sure we refer correctly to our independent instance.

myPythonBridge newCommandStringFactory
	script: 
'def fac(n):
	if n < 2:
		return 1
	else:
		return n * fac(n - 1)';
	resultExpression: 'fac(5)';
	sendAndWait
  

The fac definition is now know in the Python process

myPythonBridge newCommandFactory
	<< (#fac callWith: { 7 });
	sendAndWait
  

Python snippets always use the global unique instance and can only use an independent instance by adopting it.

PBApplication uniqueInstance: myPythonBridge
  
fac(5)
  

Don't forget to stop the instance when you are done with it.

myPythonBridge stop