0

Не работают несколько потоков, запускается всего один, много вариантов перепробовал, но что то не пойму

import random, time
from threading import Thread

class Bot:
    def __init__(self, name):
        self.name = name
        self.gold = 1
        Bot.game(self)

        
    def game(self):
        print(f"у {self.name} | {self.gold} - денег")
        self.gold += Bot.gold(self)
        time.sleep(1)
        Bot.game(self)

    def gold(self):
        return random.randint(1,self.gold)



for i in range(10):
    th = Thread(target=Bot(i))
    th.start()
1
  • Прикрепите код текстом, а не скриншотом. Так будет лучше.
    – user361068
    22 ноя 2020 в 13:45

1 ответ 1

1

Я не разбираюсь в модуле threading но так у меня все заработало

import random, time
from threading import Thread

class Bot:
    def __init__(self, name):
        self.name = name
        self.gold = 1
        Bot.game(self)
        
    def game(self):
        print(f"у {self.name} | {self.gold} денег")
        self.gold += Bot.gold(self)
        time.sleep(1)
        Bot.game(self)
    
    def gold(self):
        return random.randint(1, self.gold)
    
for i in range(10):
    th = Thread(target = Bot, args = (i, ))
    th.start()
1
  • да... спасибо.. хех
    – Merka
    22 ноя 2020 в 13:56

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.