Jump to content


Photo

Plugin programming: HTTP post request while zapping makes the zap slow


  • Please log in to reply
7 replies to this topic

#1 hyperonex

  • Senior Member
  • 82 posts

+7
Neutral

Posted 1 November 2016 - 17:44

Hi,

 

I'm implementing a plugin which posts data to an HTTPS url when the user moves from one service to another. The problem is that enigma2 displays the spinner and the zap action takes 2 or 3 seconds to finishes.

 

My implementation is as follow:

Current service -> Zap -> Call function sending HTTP post request ->New Service

 

Is there any thread like mechanism where the called function is executed in parallel with the zap action as follows:

 

Current service->Zap->New service

                             |

                              ----->Call function sending HTTP post request

 

Thanks for your help.



Re: Plugin programming: HTTP post request while zapping makes the zap slow #2 hyperonex

  • Senior Member
  • 82 posts

+7
Neutral

Posted 17 November 2016 - 17:33

I tried to run the HTTP post request within a function called through a Timer but I get the same behavior where the spinner appears when I move from one service to another. Is there any mechanism to perform the HTTP request in an asynchronous manner ???



Re: Plugin programming: HTTP post request while zapping makes the zap slow #3 athoik

  • PLi® Core member
  • 8,458 posts

+327
Excellent

Posted 17 November 2016 - 17:40

Maybe you cn create a new thread and make the request in the new thread?
Wavefield T90: 0.8W - 1.9E - 4.8E - 13E - 16E - 19.2E - 23.5E - 26E - 33E - 39E - 42E - 45E on EMP Centauri DiseqC 16/1
Unamed: 13E Quattro - 9E Quattro on IKUSI MS-0916

Re: Plugin programming: HTTP post request while zapping makes the zap slow #4 MiLo

  • PLi® Core member
  • 14,055 posts

+298
Excellent

Posted 17 November 2016 - 18:20

Read the Python twisted documentation. That's the framework Enigma2 is running on. The request will run asynchronous and you'll get callback when it's done. No threading required.
Real musicians never die - they just decompose

Re: Plugin programming: HTTP post request while zapping makes the zap slow #5 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 17 November 2016 - 18:22

May do request through twisted web so the service moves to next without waiting for the response
Edit sorry posted before i see milo post

Edited by mfaraj57, 17 November 2016 - 18:24.


Re: Plugin programming: HTTP post request while zapping makes the zap slow #6 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 17 November 2016 - 19:17

from twisted.web import client
webfile="http://..."
localfile="/tmp/test"
client.downloadPage(webfile,localfile).addCallback(downloadback).addErrback(downloaderror)
				
def downloadback(,data):
        
        if data:
            print data
def downloaderror(error):
                       
                      if error:
                          print error

example of twisted web



Re: Plugin programming: HTTP post request while zapping makes the zap slow #7 hyperonex

  • Senior Member
  • 82 posts

+7
Neutral

Posted 17 November 2016 - 19:43

from twisted.web import client
webfile="http://..."
localfile="/tmp/test"
client.downloadPage(webfile,localfile).addCallback(downloadback).addErrback(downloaderror)
				
def downloadback(,data):
        
        if data:
            print data
def downloaderror(error):
                       
                      if error:
                          print error

example of twisted web

 

 

Thanks mfaraj57!

 

Do you have any example using a POST HTTPS request with digest authentication??



Re: Plugin programming: HTTP post request while zapping makes the zap slow #8 hyperonex

  • Senior Member
  • 82 posts

+7
Neutral

Posted 17 November 2016 - 20:06

Maybe you cn create a new thread and make the request in the new thread?

 

It works well thanks!




5 user(s) are reading this topic

0 members, 5 guests, 0 anonymous users