N
Nikolay Diakov
Dear Python fans,
I recently selected Python as scripting engine for our research project.
This implies my beginner experience with Python.
Let me explain the background of the problem I want to solve.
Our research group has designed a formal language for building
special "connectors" which allow one to specify formally and
explicitly the cooperative behavior of some component instances.
We define a component instances as a black box with at least
one live animal (thread/process) inside which can communciate
with the outside environment through special holes we call "channel
ends". The formalism of the language defines the primitives a
component instance can perform on channel ends.
We have built a simulator in C++ for the our language.
We want to design a special type of component instance called
a "scriptbox" which runs a Python script. This week I have
successfully linked CPython to our applciation and have called
Python functions and have let Python functions call back the C++
API of our language (embedding and extending Python at the
same time).
Now, since our simulator can have multiple instances of
script boxes, we would like to have them execute Python scripts
concurrently. I wonder, do you guys have any good idea to
allow concurrent execution of Python scripts, which call back
the C++ API of our language (the simulator will further deal with
synchronization issues internally)?
Yesterday I read about the threading module of Python (basically
Java-like, thus quite familiar) and I think of the following solution:
Using the Python C API for every scriptbox instance I will
instantiate a custom thread object, the run method of which
will evaluate the specific Python script for that scriptbox.
Now, I have read about the limitations of Python threads
concerning their actual paralelism (as compared to OS
processes) and I can live with those. Do you think this will
work?
Best regards,
Nikolay
I recently selected Python as scripting engine for our research project.
This implies my beginner experience with Python.
Let me explain the background of the problem I want to solve.
Our research group has designed a formal language for building
special "connectors" which allow one to specify formally and
explicitly the cooperative behavior of some component instances.
We define a component instances as a black box with at least
one live animal (thread/process) inside which can communciate
with the outside environment through special holes we call "channel
ends". The formalism of the language defines the primitives a
component instance can perform on channel ends.
We have built a simulator in C++ for the our language.
We want to design a special type of component instance called
a "scriptbox" which runs a Python script. This week I have
successfully linked CPython to our applciation and have called
Python functions and have let Python functions call back the C++
API of our language (embedding and extending Python at the
same time).
Now, since our simulator can have multiple instances of
script boxes, we would like to have them execute Python scripts
concurrently. I wonder, do you guys have any good idea to
allow concurrent execution of Python scripts, which call back
the C++ API of our language (the simulator will further deal with
synchronization issues internally)?
Yesterday I read about the threading module of Python (basically
Java-like, thus quite familiar) and I think of the following solution:
Using the Python C API for every scriptbox instance I will
instantiate a custom thread object, the run method of which
will evaluate the specific Python script for that scriptbox.
Now, I have read about the limitations of Python threads
concerning their actual paralelism (as compared to OS
processes) and I can live with those. Do you think this will
work?
Best regards,
Nikolay