Ahmed Al-haddad
Ahmed Al-haddad

Reputation: 833

'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. You can see at 386 till 400, only SRDEAFUALT1234 was sending while 1.5-PC (my code) hanged or something!

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?!

Upvotes: 0

Views: 458

Answers (1)

Adrian
Adrian

Reputation: 74

I would suggest to replace pass with print 'timeout' to see what happens.

Upvotes: 1

Related Questions