Do you have Python3 installed on your machine and know how to use Perun2? If yes, we can start.
To simply run a Python3 program, use the syntax below.
Put the first code in Perun2 and the second in your Python3 file at path c:/path/to/file.py.
You can attach some data to the Python3 program. For example, send a list of files.
This is the standard command-line interface. We use the sys library in Python3 to read the arguments.
The function askPython3() calls the function main() of a Python3 script file. Then, it takes a boolean value from it and sends it back to Perun2.
All possible failures make this function return false. For example, wrong return types or exceptions thrown by Python3.
You can use external Python3 libraries. Make sure all necessary dependencies are installed.
This small program picks all pdf files whose titles start with the word Invoice. With Python3 libraries, the possibilities are endless.
The integration between Perun2 and Python3 is quite tight. For example, every log message printed in Python3 behaves as if it was printed in Perun2. Special Perun2 performance improvement settings (like turned off logs) apply to the Python3 part as well.
The function askPython3() is more performant than typical shell solutions. It keeps one running Python3 process and Perun2 communicates with it when it needs a value. Both processes share the same memory and the communication is with little delay. A single execution of askPython3() can take as little as 0.1 milliseconds. Performance bottlenecks usually lie on the Python3 side.
The performance could even improve. There are plans to introduce hidden multi-threading for Perun2. Essentially, multiple Python3 processes could work together like a thread pool. In this scenario, Perun2 with Python3 could outperform typical single-threaded Python3 programs. The code interface would remain unchanged. Users would benefit from parallelism without even caring about it.