GridServer is a bus. But it include some advanced capabilities beyon pure sub/unsub classical bus feature, such as microserver deployement, or KeyValue in memory embeded database and…
Python Instant execution feature !
Better code chunk than long story 😉
Show me the code
Here is a delphi (Pascal object) exemple :
lconnectResp := lCli.Connect('admin','admin',TGRIDProtocolFormat.Binary); if lConnectResp.Status then begin Writeln('Connected to GRID admin protocol - Welcome'); Writeln('Protocol '+lcli.Protocol.ProtocolNameSlashFormat);
You can do many things, such as get server informations :
lInfoResp := lCli.Infos; if lCli.LastStatus then begin Writeln('GRIDServerName : '+lInfoResp.GRIDServerName+' '+lInfoResp.GRIDArch+' ('+lInfoResp.GRIDCompiler+')'); Writeln('ServerGenuineName -> '+lInfoResp.ServerGenuineName); Writeln('ServerHostCPUArchitecture -> '+lInfoResp.ServerHostCPUArchitecture); Writeln('ServerHostArchitecture ->'+lInfoResp.ServerHostArchitecture); Writeln('ServerHostOS ->'+lInfoResp.ServerHostOS); Writeln('ServerHostOSBuild ->'+lInfoResp.ServerHostOSBuild); end
But keep focus on python !
Get current Python version Server side :
And now, run a python code !
lCli.instantPythonRun('def gridmain():'+sLineBreak+' print("hello world".upper())')
Pretty simple ! You will note that the python code is a bit special, because it define a method (python’s function) “gridmain()”. I’ll talk about that later, it is as is for instance to be conforme to “multithread” execution of the stuff. You can execute legacy normal code too.
For sure, that’s work on all other platforme, (c#, python itself, cpp) since GRID Server main protocole can handle json or binary format on the same port. (pure cpp binary protocol is in test, open source delivery soon ;))
the very nice part, is that this execution take inside python env : All the libs you previously installed on your python env will be available (such as PIL, numPi, or whatever) in this interface !
so, the very all power of python is available via GRID Server, on your app (here delphi), without embedded heavy library !
Ok, just before that, you have juste to enable grid server to run Python :
To do that you must have a python installed (2.x or 3.x as you want, or even many different installation : Grid know how to manage that, and it can manage multi python version.
Now, GS Part : go to the Grid Server command line (on another instance for exemple) and fellow this step :
- admin mode, by typing “admin” under GS console
- Select python management (2)
- Enter python version MAJOR.MINOR
- Enter API Version (not relevant for instance) – enter whatever you want.
- Enter the name of the lib (without path)
- Enter the path of the lib (without file name)
- Select (1) to view the current selection
- And finaly, select 4 to define default python version for InstantPython feature
- In our case (above), we put “1” when system asks for “define Default ID”.
Here it is ! Python is now ready to be invoke trought GRID Server’s KissB API. Enjoy !