Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

347
Views
Python: How to use POST or GET methods in infinite loop?

I have a simple json REST server on my LAN. I need to let clients on the LAN POST/PUT and GET camera live stream seamlessly over http. I tried two simple approaches:

Method1 (without Session):

while (frame):
   dict_obj = image_to_dict_converter(frame)
   json_obj = str(json.loads(dict_obj))
   requests.put(url, headers=headers, data = json.dumps({'data': str(json.loads(json_obj))}), timeout = 0.1)

Method2 (with Session):

ses = requests.Session()
while (frame):
   dict_obj = image_to_dict_converter(frame)
   json_obj = str(json.loads(dict_obj))
   ses.put(url, headers=headers, data = json.dumps({'data': str(json.loads(json_obj))}),timeout = 0.1)

Same methods are used withGET. I tried both on Apache2 and Nginx, and since Nginx resulted in better performance, my REST server is now linked to Nginx. I am able to stream and visualize the video on a client-server-client topology. Method2 works smoothly (~0 sec latency) and at high fps, it however freezes once a while for 6 seconds (probably Session is limited to a number of calls). Method1 works reliably, however, at low fps and with 0.5 sec constant latency in frames.

My question is how can I technically improve the methods for realtime services? (Can anyone provide an example?) Also, how can I tune Nginx to handle such service in terms of speed and number of requests?

UPDATE:
I noticed that web server (Nginx) is interrupting the stream, it has no issues when requests are redirected directly to the port number my REST listens to (localhost:8888) instead of localhost (managed by Nginx)

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!