T
T
TheRaccer2021-01-01 15:32:04
Python
TheRaccer, 2021-01-01 15:32:04

How to solve the problem with multiprocessing (Windows)?

Dealing with multiprocessing, I ran into such a problem.

def start():
  print(f"[{multiprocessing.current_process().name}]")

@bp.on.chat_message(text=["дуэль <member>", "дуэль"])
async def shot_handler(message: Message, member = None):
  if member is None:
    await message.answer("Укажите вашего соперника через @...")
  else:
    try:
      players.append([message._mention.id, message.from_id])
      if __name__ == '__main__':
        multiprocessing.Process(target = start, name = f"{message._mention.id}").start()
    except:
      await message.answer("Возможно вы допустили ошибку")


This code was written for the VK bot on the vkbottle module, for clarification, the bot is fully functional.
To implement a certain game in a bot, I decided to use multiprocessing. I am creating a process and also created a function for a test. The code should create a process after certain messages, but it doesn't throw any errors and nothing just happens.
Help deal with this problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-01-01
@bacon

You have async here, inside it it is customary to run all tasks asynchronously, and if it is a blocking task, then through run_in_executor there you can already select a process or thread as an executor

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question