How to solve this problem with Python

Posted by morpheous on Stack Overflow See other posts from Stack Overflow or by morpheous
Published on 2010-05-21T10:37:09Z Indexed on 2010/05/21 10:40 UTC
Read the original article Hit count: 213

Filed under:

I am "porting" an application I wrote in C++ into Python.

This is the current workflow:

  1. Application is started from the console
  2. Application parses CLI args
  3. Application reads an ini configuration file which specifies which plugins to load etc
  4. Application starts a timer
  5. Application iterates through each loaded plugin and orders them to start work. This spawns a new worker thread for the plugin
  6. The plugins carry out their work and when completed, they die
  7. 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:

  1. Encapsulate the whole application in a package which is executable (i.e. can be run from the command line with arguments.

  2. Write the plugins as modules (I think maybe its better to implement each module in a separate file?)

  3. 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.

© Stack Overflow or respective owner

Related posts about python