简体   繁体   中英

'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. My friend also has the same type of code but it is in C. I am using requests library. 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

My code - 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'以查看会发生什么。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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