Giter VIP home page Giter VIP logo

Comments (4)

jimmo avatar jimmo commented on May 18, 2024 1

I looked at this from the MicroPython uasyncio side. Using the tinyweb's examples/hello_world.py example, but with some sleeps shows the behavior @UnexpectedMaker describes, however if you connect manually (e.g. via telnet) you can see that the data is flushed immediately. This is just how browsers work. It seems that you need to get past some minimum number of bytes in the response before the browser will start rendering the page, e.g. this works fine:

@app.route('/')
async def index(request, response):
    # Start HTTP response with content-type text/html
    await response.start_html()
    # Send actual HTML page
    await response.send('<html><body><h1>Hello</h1>\n')
    await response.send(' ' * 1024)   # <-- Make the browser start rendering.
    for _ in range(5):
      await uasyncio.sleep(5)
      await response.send('<h2>hello</h2>\n')
    await response.send('</html>\n')

FYI @belyalov , MicroPython is going to release a new version of uasyncio soon. See micropython/micropython#5332
Unfortunately this will break TinyWeb due to some internal dependencies it has on (for example uasyncio.IORead ) For the most part, moving to uasyncio.start_server will solve this.

from tinyweb.

belyalov avatar belyalov commented on May 18, 2024

@UnexpectedMaker: @jimmo is right - this is how browser works.

Usually, to force browser to show/process received data immediately either chunks or close connection could be used.

So you can try to switch your handler to be generator (to force tinyweb to use Transfer-Encoding: chunked), like this:

async def something():
    yield '<h2>Credentials saved!</h2><br>You can now close this page...'
    yield html.format(self.web_title, st_str)
    # ...

test: https://github.com/belyalov/tinyweb/blob/master/test/test_server.py#L283
implementation: https://github.com/belyalov/tinyweb/blob/master/tinyweb/server.py#L327

from tinyweb.

belyalov avatar belyalov commented on May 18, 2024

FYI @belyalov , MicroPython is going to release a new version of uasyncio soon. See micropython/micropython#5332
Unfortunately this will break TinyWeb due to some internal dependencies it has on (for example uasyncio.IORead ) For the most part, moving to uasyncio.start_server will solve this.

This is actually great - I'll adapt tinyweb once PR merged.
Thanks

from tinyweb.

UnexpectedMaker avatar UnexpectedMaker commented on May 18, 2024

Yeah, new asyncio looks promising and much easier for noobs like me to grok!
Thanks for your help on this issue @belyalov and @jimmo - working great now, so closing it!

from tinyweb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.