Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 具有自定义事件和非阻塞的python的setInterval()等效项_Javascript_Python_Multithreading_Python Asyncio - Fatal编程技术网

Javascript 具有自定义事件和非阻塞的python的setInterval()等效项

Javascript 具有自定义事件和非阻塞的python的setInterval()等效项,javascript,python,multithreading,python-asyncio,Javascript,Python,Multithreading,Python Asyncio,我想将下面的javascript代码片段转换为python,以便于使用flask进行开发 async function run() { // TODO: If isIngame is false then getTeamData, saveJson and exit the program otherwise getPlayerData if (isIngame === false) { clearInterval(isIngame__id);

我想将下面的javascript代码片段转换为python,以便于使用flask进行开发

async function run() {
    // TODO: If isIngame is false then getTeamData, saveJson and exit the program otherwise getPlayerData 
    if (isIngame === false) {
        clearInterval(isIngame__id);
        await getTeamData();
        await saveJson();
        clearInterval(run__id);
        console.log("DONE");
        process.exit();
    } else {
        await getPlayerData();
        console.log("Running");
    }
}

isIngame__id = setInterval(() => {
    inGameStatus();
}, apiRequestPeriod);

run__id = setInterval(async() => {
    await run();
}, apiRequestPeriod);

是否有一个高效的setInterval()等价于javascript,我可以每隔1秒在两个不同的端点以非阻塞方式ping我的API?停止这两个事件的自定义事件是
inIngame
变为False。

AFAIK flask不支持异步;您应该使用quart或其他支持异步的框架。我不需要使用flask的异步。我希望程序异步运行,这样它既可以运行这些任务,又可以容纳其他添加的任务。现在你说你不需要与flask异步。Python的异步编程提供了与JavaScript非常相似的功能,但它要求整个程序从一开始就是异步的,这与Flask不同。该程序生成的输出独立于Flask。关于烧瓶,我的问题没什么好问的。