E
E
Evgeny Elizarov2014-10-29 22:01:58
linux
Evgeny Elizarov, 2014-10-29 22:01:58

Python: how to execute a script in multiple threads?

Comrades, please tell me about this issue: I use python to automate and simplify the administration of linux servers, and then the question arose - how can I execute commands in several threads?
Suppose you need to execute a command on several servers, my knowledge is enough to write all the servers to the list and loop through it, executing the command in turn on each machine, which is naturally several times longer than executing the command simultaneously on all machines. I simply do not have enough knowledge - how to do this it is necessary to contain a list of servers and how, in this case, you can run a command on each of them. So far, I have not even been able to properly formulate the question briefly in order to ask it to Google. Tell me please.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikita Lubchich, 2014-10-29
@Cybran

Not sure, but you can try to dig into Celery . I also googled the following question - I hope it helps in some way in finding a solution

V
vetash, 2014-10-30
@vetash

What if you execute a command and execute the next one without waiting for it to complete?
For example, in bash, the "&" operator is used for this.

M
MrFrizzy, 2014-10-30
@MrFrizzy

If you really want to write from scratch: 1
) multiprocessing 2
) subprocess 3 ) asynchronous
programming, I personally like gevent e (in the process of active development, but I try not to break backward compatibility ...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question