Y
Y
Yevgeni2018-06-01 16:02:04
Python
Yevgeni, 2018-06-01 16:02:04

How to run two or more functions at the same time?

I have two objects, bot1 and bot2
Each of them has a run() method.
How can I run two bots at the same time and have them run in parallel to each other?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2018-06-01
@Yevgeni

In separate coroutines , in separate threads, or in separate processes .

D
DarkMode, 2018-06-01
@DarkMode

it is also possible through asyncio

A
Alexander, 2018-06-05
@Survtur

from threading import Thread
thread1 = Thread(target=bot1.run)
thread1.start()
thread2 = Thread(target=bot2.run)
thread2.start()

But as mentioned above, this is only one of the possible ways. He just came to my mind first.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question