我用异步循环编写了一些代码:
loop = asyncio.get_event_loop()
# bla coroutines
loop.run_forever()
Run Code Online (Sandbox Code Playgroud)
现在,有人给了我使用 GObject.MainLoop() 的部分代码
l = GObject.MainLoop()
# functions using gi.repository I cannot modify, bla
l.run()
Run Code Online (Sandbox Code Playgroud)
我应该将此代码集成到与我的软件相同的软件中(使用 asyncio)。这些代码必须同时运行。代码部分必须交换对象。
我不确定哪种解决方案会被采用,或者至少不会太难看?
ps:这段代码必须在windows操作系统和python3.4上运行,所以我不能使用glub。我想我可以使用线程,但我想知道是否还有其他方法?
我终于注册了,因为我对我的问题没有更多的想法。我的后端部分使用 asyncio 和 aiohttp,前端部分使用 javascript。但是我遇到了 405 错误。(我确切地说我是这些库的初学者)
我希望从发布请求中检索 json。这里的javascript函数:
function postJson (data){
$.ajax({
url : 'http://localhost:8080/postJson',
type : 'POST',
dataType : 'json',
contentType : 'application/json',
data : data, //data are ready at json format, I do not think I need to use JSON.stringify ? I does not change anything to the error anywhere
success : function(code_html, statut){
console.log("success POST");
},
error : function(resultat, statut, erreur){
console.log("error POST");
}
});
}
Run Code Online (Sandbox Code Playgroud)
和python代码:
async def postJson(request):
data = await request.post()
#some code …Run Code Online (Sandbox Code Playgroud)