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

create a sans-io docker client class and impliment Client with blocking requests #1171

Open
graingert opened this issue Aug 25, 2016 · 7 comments

Comments

@graingert
Copy link
Contributor

graingert commented Aug 25, 2016

use https://github.com/mikeal/deferred to create a sans-io version of Client (SansIOClient) that requires something like:

class SimpleStream(object):
    def next(self) -> Deferred:
        ...

class IOAdapter(object):
    def request(self, **kwargs) -> Deferred:
        ...

    def stream(self, **kwargs) -> SimpleStream:
        ...

    def unwrap_deferred(self, deferred: Deferred) -> Any:
        ...

and then implement it with something like:

class BlockingSimpleStream(SimpleStream):
    def __init__(self, stream):
        self.generator = _stream_helper(stream):
    def next(self) -> Deferred:
        return deferred.succeeded(next(self.generator))

class BlockingIOAdapter(IOAdapter):
    def __init__(session: requests.Session):
        self.session = session

    def request(self, **kwargs) -> Deferred:
        return deferred.execute(self.session.request, **kwargs)

    def stream(self, **kwargs) -> BlockingSimpleStream:
        return BlockingSimpleStream(self.session.request(**kwargs, stream=True))

    def unwrap_deferred(self, d: Deferred):
        return deferred.waitForDeferred(d).getResult()
@graingert
Copy link
Contributor Author

graingert commented Aug 25, 2016

This way someone can come and make an asyncio IOAdapter adapter to fix #327

@graingert graingert changed the title create a sans-io docker client class and re-impliment Client with blocking requests create a sans-io docker client class and impliment Client with blocking requests Aug 25, 2016
@graingert
Copy link
Contributor Author

This won't change too much of the implimentation of api classes, they will just need to add @defered.inlineCallbacks to their methods, and then instead of:

resp = self._request(...);

do:

resp = yield self._request(...);

@graingert
Copy link
Contributor Author

@bfirsh is this something you'd like a PR on?

@graingert
Copy link
Contributor Author

@shin- this issue is completely unrelated

@shin- shin- reopened this Oct 6, 2016
@shin-
Copy link
Contributor

shin- commented Oct 6, 2016

Correct, sorry.

@graingert
Copy link
Contributor Author

@shin- is this something you guys would be interesting? It would take me a little bit of work up-front, so I'd like to know if this feature is something you would be interested in having.

@cecton
Copy link
Contributor

cecton commented May 5, 2017

I made a small attempt here to get docker-py asynchronous: https://github.com/tenforce/docker-py-aiohttp This is actually a wrapper around docker-py. I suppose it's not really what you want, especially since it is strongly bound to aiohttp and I think you want something more generic right?

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

3 participants