Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do multiple http_get url and get all responses, then return all responses to main() #7

Open
monexiao opened this issue Mar 27, 2018 · 0 comments

Comments

@monexiao
Copy link

I am a newbie for using this library.
I want to call an sub-function in main() to do http_get multiple urls, and return all responses by dict().
But I don't how to use this python 2.7 sample code to finish it.
I try to move code from main() to other sub-function and use returnValue(dict()) to return to main(), but the program exits when inlineCallbacks sub-function is done, so main function can not do anything after calling sub-function.
Could anyone can give some idea or direction? Thanks a lot.

from twisted.internet.defer import inlineCallbacks
from twisted.internet.task import react
from requests_threads import AsyncSession

session = AsyncSession(n=100)

@inlineCallbacks
def main(reactor):
    responses = []
    for i in range(100):
        responses.append(session.get('http://httpbin.org/get'))

    for response in responses:
        r = yield response
        print(r)

if __name__ == '__main__':
    react(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant