How to solve this problem with Python
- by morpheous
I am "porting" an application I wrote in C++ into Python.
This is the current workflow:
Application is started from the console
Application parses CLI args
Application reads an ini configuration file which specifies which plugins to load etc
Application starts a timer
Application iterates through each loaded plugin and orders them to start work. This spawns a new worker thread for the plugin
The plugins carry out their work and when completed, they die
When time interval (read from config file) is up, steps 5-7 is repeated iteratively
Since I am new to Python (2 days and counting), the distinction between script, modules and packages are still a bit hazy to me, and I would like to seek advice from Pythonista as to how to implement the workflow described above, using Python as the programing language. In order to keep things simple, I have decided to leave out the time interval stuff out, and instead run the python script/scripts as a cron job instead.
This is how I am thinking of approaching it:
Encapsulate the whole application in a package which is executable (i.e. can be run from the command line with arguments.
Write the plugins as modules (I think maybe its better to implement each module in a separate file?)
I havent seen any examples of using threading in Python yet. Could someone provide a snippet of how I could spawn a thread to run a module. Also, I am not sure how to implement the concept of plugins in Python - any advice would be helpful - especially with a code snippet.