pythonpython-3.xgeventslack-apigreenlets

Gevent task with endless loop seems to block every other task aswell


I'm quite new to Gevent/Greenlet and have gone through the tutorials. I would like to run a bot for each registered team.

for bot in self.bots:
    events.append(gevent.spawn(bot.start))
gevent.joinall(events)

The interesting part is that if I don't use a while true loop, I get the bot_id of both bots shown in the console.

def start(self):
        while True:
            for reply in self.slack_client.rtm_read():
                self.input(reply)
            time.sleep(0.1)
            logger.info("Log:{0}".format(self.bot_id))

But as soon as I use a endless loop, I can only see one bot's id being displayed. It seems as if the other task is waiting for this one to finish, which makes no sense. I thought that gevent.joinall would run both in parallel.

any advice on this please?

UPDATE

For the record, I had to add gevent.sleep(0.1) on the last line of while loop to make this work.


Solution

  • From the Gevent introduction:

    Only one greenlet is ever running at any given time.

    Basically I think that what you are looking for is parallelism not asynchronous operations. Maybe a better fit would be to use the multiprocessing module.