首页 > 解决方案 > 为什么线程(使用 python)可以在 Windows 上工作,但不能在 Mac 上工作?

问题描述

每次我们尝试在 Mac 上运行代码时都会出现错误。它应该在游戏开始之前绘制一个“蛇”标签。这是为什么?其余代码是典型的蛇游戏代码,通常在任何地方都可以使用。为此,我们与 Pygame 合作。这是代码:

import threading

def draw_logo():
cord_list = ["71,100 129,100", "75,100 75,155",
             "75,150 130,150", "125,150 125,205",
             "125,200 71,200", "175,205 175,150",
             "175,150 175,95", "175,95 225,155",
             "225,150 225,95", "225,150 225,205",
             "275,205 275,150", "275,150 275,96",
             "275,100 325,100", "325,96 325,150",
             "325,150 325,205", "275,150 325,150",
             "375,205 375,150", "375,150 375,95",
             "375,150 400,150", "400,150 425,95",
             "400,150 425,205", "525,100 475,100",
             "475,96 475,150", "475,150 475,205",
             "475,200 525,200", "475,150 500,150"]

for cord in cord_list:
    start, end = cord.split(" ",1)
    pg.draw.line(window, malachite, tuple(map(int,start.split(","))), tuple(map(int,end.split(","))), 10)
    time.sleep(0.05)
    pg.display.update()
    if stop_threads:
        break

stop_threads = False

th_draw = threading.Thread(target=draw_logo)

th_draw.start()

#after a button is pressed, variable stop_threads = True to start the game immediately
stop_threads = True

这是错误消息:

pygame 2.0.1 (SDL 2.0.14, Python 3.7.9) 来自 pygame 社区的问候。pygame.org/contribute.html -[MTLIOAccelCommandBuffer validate]:208: 断言失败“使用未提交的编码器提交命令缓冲区”后端终止或断开连接。使用“停止/重新启动”重新启动。

标签: pythonmacos

解决方案


推荐阅读