Python: simple async download of url content?

后端 未结 10 1529
天命终不由人
天命终不由人 2020-12-15 11:23

I have a web.py server that responds to various user requests. One of these requests involves downloading and analyzing a series of web pages.

Is there a simple way

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 12:23

    I'm not sure I'm understanding your question, so I'll give multiple partial answers to start with.

    • If your concern is that web.py is having to download data from somewhere and analyze the results before responding, and you fear the request may time out before the results are ready, you could use ajax to split the work up. Return immediately with a container page (to hold the results) and a bit of javascript to poll the sever for the results until the client has them all. Thus the client never waits for the server, though the user still has to wait for the results.
    • If your concern is tying up the server waiting for the client to get the results, I doubt if that will actually be a problem. Your networking layers should not require you to wait-on-write
    • If you are worrying about the server waiting while the client downloads static content from elsewhere, either ajax or clever use of redirects should solve your problem

提交回复
热议问题