首页 > 解决方案 > 对象没有被存储和从多处理队列中提取

问题描述

import discord
import pyboy
import multiprocessing

from discord.ext import commands
from pyboy import PyBoy, WindowEvent

client = commands.Bot(command_prefix = ',')
pyboy = PyBoy('pokemonYellow.gb', sound=True)
q = multiprocessing.Queue()

def token(): 
    return client.run('')

def emulator(): 
    pyboy = PyBoy('pokemonYellow.gb', sound=True)

    while True: 
        try: 
            pyboy.send_input(q.get_nowait())
        except:
            pass
        
        if pyboy.tick(): 
            return 
   
@client.command(brief = "presses the start button")
async def start(ctx): 
    q.put(WindowEvent.PRESS_BUTTON_START)

@client.command(brief = "presses the select button")
async def select(ctx): 
    q.put(WindowEvent.PRESS_BUTTON_SELECT)

@client.command(brief = "presses the a button")
async def a(ctx): 
    q.put(WindowEvent.PRESS_BUTTON_A)

@client.command(brief = "presses the b button")
async def b(ctx): 
    q.put(WindowEvent.PRESS_BUTTON_B)

@client.command(brief = "presses the up button")
async def up(ctx): 
    q.put(WindowEvent.PRESS_ARROW_UP)

@client.command(brief = "presses the down button")
async def down(ctx): 
    q.put(WindowEvent.PRESS_ARROW_DOWN)

@client.command(brief = "presses the left button")
async def left(ctx):
    q.put(WindowEvent.PRESS_ARROW_LEFT)

@client.command(brief = "presses the right button")
async def right(ctx): 
    q.put(WindowEvent.PRESS_ARROW_RIGHT)

def main(): 
    process1 = multiprocessing.Process(target = token)   
    process2 = multiprocessing.Process(target = emulator)

    process1.start()
    process2.start()

if __name__ == "__main__": 
    main()

afai 可以判断对象正在被放入队列中,但是有东西正在吃掉它们并且它们没有出来。任何帮助,将不胜感激。我也尝试将 discord.py 的东西扔到它自己的函数中,但这没有帮助。由于 pyboy 的怪异行为,我不能为此使用线程。

标签: pythonpython-3.xmultiprocessingdiscord.py

解决方案


推荐阅读