R
R
Roma2021-06-09 10:37:42
Python
Roma, 2021-06-09 10:37:42

How to run multiple python files at the same time?

Hello, I want to run 2 bots at the same time, but it doesn't work

import bot_1, bot_2
from threading import Thread

Thread(target=bot_2.main).start()
Thread(target=bot_1.main).start()

This code launches the bot_1 file, but it does not launch bot_2, what is the reason for this?

PS there are no errors in the codes, I ran them separately and everything works fine)
I want to run them through a file, and not through the console, run it like this just in case
I would be glad if you help (

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Krostelev, 2021-06-09
@twistfire92

So run them separately. Why do you need to combine them in one process?

F
full_stack_newbie, 2021-06-09
@full_stack_newbie

Wrap the start of the bot not in main but in the usual function startbotX and start like this

if __name__ == '__main__':
    Thread(target = startbot1).start()
    Thread(target = startbot2).start()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question