lundi 8 novembre 2021

What is best practice for creating a "chain of processes" in python?

I create a program which allows the user to execute several functions via a GUI. Let's say there are n functions from f1 to fn. A function could be to send data to a socket, calculate some values etc.

Some buttons in my GUI do not start a single function, but instead create something like a "process", which is essentially the sequential execution of multiple functions with certain parameters. So for example, a certain Button invokes f1 with parameters p1, afterwards f3 with parameters p... and so on. Depending on the process, some functions are allowed to give output and some aren't.

Since putting all that logic in my GUI-related code would get messy really fast, I am trying to relocate it to some other place. So far I tried creating a dict which holds the information of each "process": Which function to start first, which parameters to use, allowing output, etc. Then in a class (Let's call it C) I loop over this dict and execute each of these functions. In the GUI-related code I then just initialize the class with the name of the "process chain" and start the execution of the chain.

Is there a better way to do this? What's the best way of creating these kind of "process chains"?

Aucun commentaire:

Enregistrer un commentaire