Which Python async library would be best suited for my code? Asyncore? Twisted?

前端 未结 3 2051
礼貌的吻别
礼貌的吻别 2020-12-04 16:58

I have a program I\'m working on that will be reading from two \'network sources\' simultaneously. I wanted to try out an asynchronous approach rather than use threading. Th

3条回答
  •  不思量自难忘°
    2020-12-04 17:48

    Asyncore is nice but not very feature rich so you might run into problems later when your app grows. That being said, it's great to prototype stuff. The approach is quite simple. You define methods to handle certain events in a class (when read is possible, when write is possible etc) and then subclass that from the asyncore.dispatcher (I think) class.

    The official docs for the module as well as Doug Hellmann's excellent PyMOTW article on it are good sources to check out for docs and examples.

    If your protocol is conversational (e.g. send this, receive that), you can check out the asynchat module also distributed with the standard library for ideas.

    Twisted is a much more heavy duty approach. I'm sure it will work better for larger projects given how much it's used but I can't say anything more because I don't have any first hand experience with it.

提交回复
热议问题