Failed to launch Psychopy window within Flask framework

36 Views Asked by At

I would like to implement the following functionality: launching Psychopy when a user sends a request. This is my code.

import datetime
from psychopy import visual, core, event

class Paradigm:
    def __init__(self):
        self.devices = devices

        self.fresh_rate = fresh_rate  # 60Hz
        self.sti_show_time = sti_show_time  # 0.5s
        self.frame_num_of_a_sti = int(self.sti_show_time * self.fresh_rate)

        self.sti_list = ["paradigms/pic/a.jpg", "paradigms/pic/b.jpg"]

    def run(self):
        print(self.sti_list)
        self.window = visual.Window(allowGUI=False, units="pix", screen=0, fullscr=True, color=[-1, -1, -1])
        self.instruction = visual.TextStim(self.window, color=(255, 255, 255), text="Start", height=70, font="simhei")

        self.instruction.draw()
        self.window.flip()
        core.wait(2)

        for sti_path in self.sti_list:
            self.sti_imag = visual.ImageStim(self.window, image=sti_path, size=self.window.size)

            self.window.callOnFlip(self.__add_mark, 1)
            for _ in range(self.frame_num_of_a_sti):
                self.sti_imag.draw()
                self.window.flip()

        self.instruction.text = "End"
        self.instruction.draw()
        self.window.flip()
        core.wait(2)

        self.window.close()

from flask import Flask
from flask_cors import CORS

from paradigms import Paradigm

para = Paradigm()

app = Flask(__name__)
CORS(app, supports_credentials=True)

@app.route("/paradigm")
def run_paradigm():
    para.run()

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=19782)

When I run the program and send a request to http://127.0.0.1:19782/paradigm, I encounter the following error: pyglet.gl.lib.MissingFunctionException: wglChoosePixelFormatARB is not exported by the available OpenGL driver. ARB_pixel_format is required for this functionality.

May I ask how to resolve this?

0

There are 0 best solutions below