Coder Social home page Coder Social logo

Comments (6)

Mixser avatar Mixser commented on July 23, 2024 3

@rkrell

Thanks for notice. As I can see, you are using threads (and pypy) and we didn't tested our lib in such way of usage.

May be the asyncio.set_event_loop method will be useful for you cases. I mean you need to connect the event loop to your threads before using the async methods in it.

If you did it and the problem still happening, notify us.

And thanks for your PR. 😊

from gmqtt.

rkrell avatar rkrell commented on July 23, 2024

Thanks for merging, the above traceback does no longer occur now.

Would appreciate a release just in case of some spare time ;-) Thank you in advance

from gmqtt.

rkrell avatar rkrell commented on July 23, 2024

The async_to_sync wrapper is just a workaround, because I need to call async methods from within the gmqtt callbacks. Best would be having coroutines as callbacks, that would simplify it a lot.

Thank you all for acting so fast.

from gmqtt.

Mixser avatar Mixser commented on July 23, 2024

Hi,

We support an async callback only for on_message. May be it will help you.

Also you always can add coroutine to event loop from sync method in this way:

async def example(*args, **kwargs):
    # do async stuff
    pass

def on_message(*args, **kwargs):
    asyncio.ensure_future(example(*args, **kwargs)

from gmqtt.

rkrell avatar rkrell commented on July 23, 2024

Aha, I see now:

gmqtt/gmqtt/mqtt/handler.py

Lines 296 to 299 in d198e5b

if iscoroutinefunction(self.on_message):
asyncio.ensure_future(self.on_message(self, print_topic, packet, qos, properties))
else:
self.on_message(self, print_topic, packet, qos, properties)

Very good solution, to be able to use sync and async according to the needs.
This will help much avoiding workarounds. Thanks.

from gmqtt.

rkrell avatar rkrell commented on July 23, 2024

Also you always can add coroutine to event loop from sync method in this way:

async def example(*args, **kwargs):
    # do async stuff
    pass

def on_message(*args, **kwargs):
    asyncio.ensure_future(example(*args, **kwargs)

Good point, will try this.

from gmqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.