首页 > 解决方案 > 带有不和谐 RPC 的 Python 线程

问题描述

问题:它不运行thread_3 什么是thread_3?它是一个不和谐的 rpc(例如连接到您的不和谐应用程序:您可以使用它设置游戏活动)我不知道为什么它不起作用。我是多线程/线程的新手。也许有人可以帮助我,谢谢!

import _thread as thread
import time
from pypresence import Presence

cid = int(785560652756418621)
rpc = Presence(cid)

# Define a function for the thread
def print_time( threadName, delay):
   count = 0
   while count == count:
      time.sleep(delay)
      count += 1
      print ("%s: %s" % ( threadName, time.ctime(time.time()) ))

def print_test( threadName, delay):
    count = 0
    while count == count:
      time.sleep(delay)
      count += 1
      print ("%s: %s" % ( threadName, delay))
      
def thread_3(delay):
        count = 0
        while count == count:
            time.sleep(delay)
            count += 1
            # Connect to Discord
            rpc.connect()
            
            rpc.update(small_image = '512', large_image = '512',state = "Test",details = "Test", small_text="Test", large_text="Test")
            print('RPC set successfully.')
            # Update RPC every 15 seconds
            while True:
                time.sleep(10)
  
# Create two threads as follows
try:
   thread.start_new_thread( print_time, ("Thread-1", 2) )
#    thread.start_new_thread( print_test, ("Thread-2", 4) )
   thread.start_new_thread( thread_3, ("Discord-3", 3) )
except:
   print ("Error: unable to start thread")

while 1:
   pass

标签: pythonpython-3.xmultithreadingmultiprocessingdiscord

解决方案


推荐阅读