I am writing a python game script and I wanted to know how to make my code run simultaniously with multiprocessing, I have this following code and basically what I have is my def moving_on
function looping every 2 seconds and then I'll use another function def test(self)
to check something in the game every 2 hours, that's why I need to use multiprocessing since the first def
function cannot wait 2 hours to loop.
from selenium import webdriver
from time import sleep
from login import username, password, cronometer, energy, no_energy
from multiprocessing import Process
import os
import logging
class gameBot:
def __init__(self, username, password):
(basically logs into the game with username and password)
def moving_on(self, cronometer, energy, no_energy):
(checks if its able to refill energy and refills automatically)
def test(self)
logging.info("multiprocessing is working...")
if __name__ == '__main__':
bot=gameBot(username, password)
p1 = Process(target=bot.moving_on, args=(cronometer, energy, no_energy))
p2 = Process(target=bot.test)
p1.start()
p2.start()
p1.join()
p2.join()
if I run the script normally, without multiprocessing, simply by writing this at the bottom:
bot=gameBot(username, password)
bot.moving_on(cronometer, energy, no_energy)
then it works fine, but like I explained that's not what I need.
and if I run the script using (or at least trying to) the multiprocessing method like shown on the first code above, it logs into the game site with username and password, goes to the main page but then gives me an error on p1.start()
, error: (Exception has occurred: EOFError Ran out of input
)