Multiprocessing not working?

Ok, so in the following code it’s a very simple discord bot which is supposed to start a loop when someone’s message starts with “.loop”. However with the command being typed the loop or the process does not start. What is the reasoning for this?

import discord
import random
import time
import multiprocessing
def boop():
  while True:
    time.sleep(1)
    print("I am looping.")

client = discord.Client()

@client.event
async def on_ready():
  print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return
  if message.content.startswith(".loop"):
    if __name__ == '__main__':
      time.sleep(1)
      p1 = multiprocessing.Process(target=boop)
      p1.start()

client.run("yes")

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.