omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    What is the proper way to make async http requests in Pythonista, without blocking UI and without ui.in_background (asyncio doesn’t allow it)?

    Pythonista
    2
    2
    1726
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • idchlife
      idchlife last edited by

      I’m making an app that will be used on 3 of my iPads via working copy and Pythonista. It will upload photos made in iPad to my server. Unfortunately, as I understand, requests is sync library, so ui thread will be locked.
      I though about aiohttp, but as I can see there is no clear way how to install it into pythonista app repo and then install it on the other devices (like I would with pipenv on my server)

      I wondered about ui.in_background, but my app already uses asyncio to the fullest (many ui updates, statuses via simple http requests to my server), so ui.in_background simply does not execute because asyncio.loop.run_until_completes does not give it opportunity to even start executing

      Thanks!

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        aiohttp can easily be installed using stash + pip.

        there is hardly ever any reason to use in_background, since those get queued up on the interpreter thread. you can define your own threading based decorator such as

        def run_async(func):
           from threading import Thread
           from functools import wraps
        
           @wraps(func)
           def async_func(*args, **kwargs):
              func_hl = Thread(target = func, args = args, kwargs = kwargs)
              func_hl.start()
              return func_hl
        
           return async_func
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB Forums | Contributors