Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

run_in_executor incorrectly identifies xmlrpclib methods as coroutines #458

Closed
jimfunk opened this issue Nov 9, 2016 · 3 comments
Closed

Comments

@jimfunk
Copy link

jimfunk commented Nov 9, 2016

If a method from an xmlrpclib ServerProxy instance is passed to loop.run_in_executor() in Python 3.5.1, it incorrectly identifies it as a coroutine.

import asyncio
from xmlrpc.client import ServerProxy


async def nonblocking(loop, proxy):
    return await loop.run_in_executor(None, proxy.system.listMethods)


loop = asyncio.get_event_loop()
proxy = ServerProxy('http://127.0.0.1/RPC2/')
loop.run_until_complete(nonblocking(loop, proxy))
@gvanrossum
Copy link
Member

Looks like this is because ServerProxy overrides __gettattr__ to treat any attribute as a potential method.

Can you work around it by wrapping the listMethods call in a lambda? E.g.

async def nonblocking(loop, proxy):
    return await loop.run_in_executor(None, lambda: proxy.system.listMethods())

For a real fix, maybe asyncio.isfuture() should check whether _asyncio_future_blocking is a bool or int? @1st1?

@1st1
Copy link
Member

1st1 commented Nov 9, 2016

asyncio.isfuture is a fairly recent addition, there is no stable Python out there with it. And the most recent version of isfuture should handle proxy & mock objects.

The problem is actually in asyncio.iscoroutinefunction, I've opened a PR to fix it: #459.

@1st1
Copy link
Member

1st1 commented Nov 15, 2016

Closing the issue, the PR to fix it has just been merged.

@1st1 1st1 closed this as completed Nov 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants