Python Forum
running 2 loops at the same time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
running 2 loops at the same time
#1
Hey,
I've created my own program, and i want my program's user's discord, to be telling that he is 'playing' my program while he is running it. I've created a function (set_discord_status) wich sets the user's discord status to: 'playing Storm Aio'. But this is a loop.. And i want this loop to run at the same time as my program. I've created a other loop (loop) wich demonstrates my program. And so, I want my program (loop - in this case) to run at the same time as the loop wich sets my discord status. i've created the code below but when I run that. It will set the discord status, but it won't run the other loop...

Does someone know what i did wrong?

from threading import Thread
import rpc
import time


def set_discord_status(): # This is a function wich sets my discord status to a specific game
    client_id = '689533785343000590'
    rpc_obj = rpc.DiscordIpcClient.for_platform(client_id)

    start_time = time.time()
    while True:
        activity = {
                "state": "Beta version: 0.0.1",
                "details": "Taking stock...",
                "timestamps": {
                    "start": start_time
                },
                "assets": {
                    "small_text": "Light",
                    "small_image": "little",
                    "large_text": "StormAIO",
                    "large_image": "default"
                }
            }
        rpc_obj.set_activity(activity)


def loop(): # This is a loop just to test if they can run at the same time
    while True:
        print('hoi')


Thread(target=set_discord_status()).start()
Thread(target=loop()).start()
Reply


Messages In This Thread
running 2 loops at the same time - by julio2000 - Mar-21-2020, 04:19 PM
RE: running 2 loops at the same time - by ndc85430 - Mar-21-2020, 04:41 PM
RE: running 2 loops at the same time - by julio2000 - Mar-21-2020, 04:44 PM
RE: running 2 loops at the same time - by ndc85430 - Mar-21-2020, 04:49 PM
RE: running 2 loops at the same time - by julio2000 - Mar-21-2020, 04:50 PM
RE: running 2 loops at the same time - by ndc85430 - Mar-21-2020, 04:54 PM
RE: running 2 loops at the same time - by julio2000 - Mar-21-2020, 05:20 PM
RE: running 2 loops at the same time - by ndc85430 - Mar-21-2020, 05:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Running an action only if time condition is met alexbca 5 1,373 Oct-27-2022, 02:15 PM
Last Post: alexbca
  Why recursive function consumes more of processing time than loops? M83Linux 9 4,317 May-20-2021, 01:52 PM
Last Post: DeaD_EyE
  Assistance with running a few lines of code at an EXACT time nethatar 5 3,326 Feb-24-2021, 10:43 PM
Last Post: nilamo
  Running multiple script at the same time LoganSulpizio 1 7,091 Dec-07-2019, 04:30 PM
Last Post: Clunk_Head
  Error when running the second time metro17 3 3,791 Aug-30-2019, 12:09 PM
Last Post: ThomasL
  Time based loops Owenix 4 3,798 Sep-20-2018, 05:37 PM
Last Post: Owenix
  Multi-processing - problem with running multiple *.py files at the same time Antonio 5 3,872 Sep-12-2018, 01:08 PM
Last Post: volcano63
  Running Date and Time in SQLITE using Python trabis03 3 4,360 Jul-17-2017, 02:10 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020