You are viewing a single comment's thread from:

RE: New LightHive release: 0.3.0

in HiveDevs3 years ago

OK trying this out... Question though, if I'm already in async code can I pass an existing loop through to it?

Exception has occurred: RuntimeError
This event loop is already running
  File "/Users/gbishko/Documents/Python-iMac/hive-lightning/v4vapi/scanner2.py", line 14, in run
    client = Client(loglevel=logging.DEBUG, automatic_node_selection=True)
  File "/Users/gbishko/Documents/Python-iMac/hive-lightning/v4vapi/scanner2.py", line 22, in <module>
    asyncio.run(run())
Sort:  

you can use

import nest_asyncio
nest_asyncio.apply()

at the top of your script (after installing nest-asyncio) for a band-aid solution. Even though node selection is async, lighthive is not async-friendly. RPC calls are all sync, at the moment, and by design lighthive is not thread-safe/concurrency-safe.

I have plans to add support for async calls, but it's not there yet. So, I would suggest not using lighthive in async environments unless you know what you're doing.

If the automatic node selection is what you need, then this module is pretty much can be used in your project:

https://github.com/emre/lighthive/blob/master/lighthive/node_picker.py

import nest_asyncio
nest_asyncio.apply()

That's working nicely but I have a question: do you have any equivalent to Beem's no_broadcast setting which I find tremendously useful in unit-tests.

I'm looking hard at building parts of this into my application now. I think we will and certainly if you continue to develop toward full async I'll be a fan.

or wait a little bit, I've plans for a lighthive-asyncio package. :)