Anyway to async call HTTP.Request or add objects to ObjectContainer?

Hello everybody,

I’m working on the LetMeStream Channel (forums.plex.tv/discussion/212686/rel-letmestream-channel#latest)

I have to make several call using HTTP.Request (basically, urls have offsets) to retrieve data.
I make a loop on it, but sometimes, there is too many call and channel time out (after refresh, with the cache it’s ok)

How can i add objects to ObjectContainer asynchronous (continue to add objects after the return) ?

Any idea with this kind of code?

@route(PREFIX + ‘/TvShows’)
def GetTvShows():
oc = ObjectContainer()
url = ‘http://blablablabla?offset=XX
offset = 0
items = JSON.ObjectFromString(HTTP.Request(url, cacheTime = CACHE_1DAY).content)[‘items’]
while len(items) > 0:

      for item in items]:
           oc.add(...)

      offset += len(items)
      url = 'http://blablablabla?offset=' + str(offset)
      items = JSON.ObjectFromString(HTTP.Request(url, cacheTime = CACHE_1DAY).content)['items']

return oc

Thanks in advance :slight_smile:

It is best, if possible, to create a separate function to handle each HTTP Request to prevent the timeouts.

If you are pulling the data from that HTTP request and plan to send it on to another function, you can include a callback to a function within a DirectoryObject and it may not cause the issues with multiple pulls/timeouts you get with multiple request in the function itself.

I haven’t used this method in a long time, but here is an example that uses a separate GetThumb function in a DirectoryObject - github.com/shopgirl284/MTVShows.bundle/blob/27866ffda853a47633c1da9fd09d5557fcf10058/Contents/Code/init.py#L108