简体   繁体   English

向服务器发送POST请求时,“请求”库暂时挂起? [蟒蛇]

[英]'Request' library hangs temporarily when sending POST requests to the server?! [Python]

I have my python code that sends data to the server every 10 seconds. 我有每10秒将数据发送到服务器的python代码。 My friend also has the same type of code but it is in C. I am using requests library. 我的朋友也有相同类型的代码,但是在C语言中。我正在使用requests库。 What I found sometimes was that my code would hang sometimes when I send the data. 我有时发现,当我发送数据时,我的代码有时会挂起。 您可以看到在386到400之间,只有SRDEAFUALT1234正在发送,而1.5-PC(我的代码)挂起了!

You can see at 386 till 400, only SRDEAFUALT1234 was sending while 1.5-PC (my code) hanged or something 您可以看到在386到400之间,只有SRDEAFUALT1234正在发送,而1.5-PC(我的代码)挂起了

My code - Python 我的代码-Python

import requests
import time
while True:
    start_time_loop = time.time() 
    source = requests.get(url)
    result = source.json()
    resp = request.post(another_url.php,json = result,headers) 

    if time.time()-start_time_loop> 10: pass 
    else : time.sleep(abs(10 - (time.time() - start_time_loop))) 

Is there something in my code that makes it lag? 我的代码中有什么东西使它滞后吗? Should I modify somthing to get better connection and performance?! 我应该修改一些东西以获得更好的连接和性能吗?

我建议将pass替换为print'timeout'以查看会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM