I'm currently doing some changes in an existing script, but the thing is, I have no experience with multithreading and the more examples that I see, the more confused I get.
Here is a little insight on what I'm trying to achieve.
The script gets 2 inputs, the service and the action, the service can use * to look for all of the services running, which causes the service to become a list stored into an array.
Now for the good part, there is a function that based on the service and the action, it performs something, i.e.
perform_service_action(service1, stop)
This will cause the service1 to stop and so on.
Unfortunately this process was configured to run sequentially and the script takes too long to process, so what I'm wondering is if any of you guys have any tips on how I should approach this, here is a small part of the code:
def main(argv):
if len(argv) == 1:
if argv[0] == 'list':
list_of_serv = get_list(None)
for service in list_of_serv:
if not service == "":
print service
else:
help()
elif len(argv) == 2:
service_arg = argv[0]
action = argv[1]
list_of_serv = get_list(service_arg)
for service in list_of_serv:
perform_service_action(service, action)
print_service_output()
else:
help()
I've tried a few things here and there but the more I try, the more I get confused with the threading topic. Is this a matter of just changing the main part of the code to run in threads the same function with different values?, or is it a matter of changing the functions from scratch, meaning the function that gets the list and the one that performs the action on the services.
I hope anyone is able to give some pointers on this.
Thanks in advance.