weixin_39643865
weixin_39643865
2020-12-02 13:22

Asyncio

Working asyncio and aiohttp implementation, replacing the requests library (for talking to bitcoind's multiple RPC threads asynchronously). You should use python 3.4.1 or newer due to this bug: http://bugs.python.org/issue20275 which results in spammy logging with --verbose. aiohttp is relatively new and you should install it from git for now. https://github.com/KeepSafe/aiohttp

It may be possible to get this to work under python 3.3 as well, but asyncio must be installed as an external package. (It comes with python 3.4).

该提问来源于开源项目:CounterpartyXCP/counterparty-lib

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

12条回答

  • weixin_39553653 weixin_39553653 5月前

    Can you make this PR against the develop branch instead?

    点赞 评论 复制链接分享
  • weixin_39553653 weixin_39553653 5月前

    Instead of wrapping all of the synchronous RPC calls with aiorun, could we wrap all of them in a function which takes an argument synchronous which defaults to True? Could we do something like this to get rid of all of those new yield froms, too?

    点赞 评论 复制链接分享
  • weixin_39643865 weixin_39643865 5月前

    Sorry I thought it was against develop... Did you pull it anyway? I'm getting a lot of errors rebasing now...

    PhantomPhreak [notifications.com] wrote:

    Can you make this PR against the develop branch instead?

    — Reply to this email directly or view it on GitHub.*

    Cheers, Bob McElrath

    "The individual has always had to struggle to keep from being overwhelmed by the tribe. If you try it, you will be lonely often, and sometimes frightened. But no price is too high to pay for the privilege of owning yourself." -- Friedrich Nietzsche

    点赞 评论 复制链接分享
  • weixin_39553653 weixin_39553653 5月前

    I didn't pull it, no.

    点赞 评论 复制链接分享
  • weixin_39643865 weixin_39643865 5月前

    I think renaming aiorun -> synch_run or something is fine, but I don't think it's possible to get rid of the yield from. You can't wrap synchronous code with a function and make it asynchronous. You CAN wrap asynchronous code with a function and wait for the result to make it synchronous. It takes a bit to wrap your head around, but the yield from are really necessary and can't be hidden. It's just that I didn't migrate lib/api.py and lib/util.py to be asynchronous.

    点赞 评论 复制链接分享
  • weixin_39553653 weixin_39553653 5月前

    I'm saying that the calls that don't need to by asynchronous (e.g. this one), don't strictly need the yield from. I guess the idea would be to wrap all of the RPC calls in a function foo() which has a parameter synchronous=True. When calling foo() synchronously, it'll return the result straightforwardly; when calling it asynchronously, it'll return a generator and yield from will need to be used. Does that make sense?

    点赞 评论 复制链接分享
  • weixin_39643865 weixin_39643865 5月前

    Can you tell me how to rebase this thing off develop? I seem to have done it in my local repo via:

    
    git rebase upstream/develop
    git push origin +asyncio
    

    but github is showing that it's still based on master.

    点赞 评论 复制链接分享
  • weixin_39553653 weixin_39553653 5月前

    I think that you have to create a new Pull Request through the GitHub interface, setting the 'base' branch to develop.

    点赞 评论 复制链接分享
  • weixin_39643865 weixin_39643865 5月前

    See #261 against develop

    点赞 评论 复制链接分享
  • weixin_39643865 weixin_39643865 5月前

    See #261 against develop

    点赞 评论 复制链接分享
  • weixin_39643865 weixin_39643865 5月前

    I don't think that will work, because the presence of yield in the wrapper function turns it into a coroutine. For example this function always returns a generator.

    
    def aiorun(x, synchronous=True):
        if synchronous:
            return asyncio.get_event_loop().run_until_complete(x)
        else:
            yield from x
    

    PhantomPhreak [notifications.com] wrote:

    I'm saying that the calls that don't need to by asynchronous (e.g. this one), don't strictly need the yield from. I guess the idea would be to wrap all of the RPC calls in a function foo() which has a parameter synchronous=True. When calling foo() synchronously, it'll return the result straightforwardly; when calling it asynchronously, it'll return a generator and yield from will need to be used. Does that make sense?

    点赞 评论 复制链接分享
  • weixin_39553653 weixin_39553653 5月前

    Alright. If there's no other obvious way of doing that, then nevermind. :)

    点赞 评论 复制链接分享

相关推荐