我想问我有一段程序,是httpServer的。内容大概是接受用户申请请求,返回他一些信息,然后再去处理这个操作!但是在实际应用,他居然变成接到用户申请请求,生成信息,然后处理动作接着再向用户传输信息。这难道是操作的函数阻塞返回信息吗?
class Handler():
def __init__(self,Msg=None):
self.Msg=Msg
def run():
if self.Msg==None:
return None
else:
'''处理用户信息'''
try:
J=json.dumps(Msg)
except:
return None
if "data" in J:
'''返回用户'''
self.Send(200,"OK")
while True:
'''处理操作'''
result=self.forwork(J)
'''等待处理结果'''
if result==True:
break
'''结束函数'''
return None
代码如上,问题就是Send函数用等到跳出循环之后,他向用户发出信息,这是为什么?
I don’t know what framework you are using. I think the reason may be that when the framework calls your run function, it waits until the execution of your function is completed before sending the message. The send function you wrote may just write to the buffer of the object first. district.