greenlets

Wait until one of several greenlets finished

霸气de小男生 提交于 2021-02-08 08:30:32
问题 I have two functions that receives data from two different connections, and i should close both connections after getting result from one of them. def first(): gevent.sleep(randint(1, 100)) # i don't know how much time it will work return 'foo' def second(): gevent.sleep(randint(1, 100)) # i don't know how much time it will work return 'bar' Then i spawn each function: lst = [gevent.spawn(first), gevent.spawn(second)] gevent.joinall blocks current greenlet until both two greenlets from lst

Can python abstract base classes inherit from C extensions?

拥有回忆 提交于 2021-02-06 16:28:49
问题 It seems as if that when I have an abstract base class that inherits from gevent.Greenlet (which inherits from the C extension module greenlet: https://github.com/python-greenlet/greenlet) then classes that implement it do not raise any of the abc errors about unimplemented methods. class ActorBase(gevent.Greenlet): __metaclass__ = abc.ABCMeta @abc.abstractmethod def foo(self): print "foo" class ActorBaseTest(ActorBase): def bar(self): print "bar" abt = ActorBaseTest() # no errors! If I

Can python abstract base classes inherit from C extensions?

旧巷老猫 提交于 2021-02-06 16:27:51
问题 It seems as if that when I have an abstract base class that inherits from gevent.Greenlet (which inherits from the C extension module greenlet: https://github.com/python-greenlet/greenlet) then classes that implement it do not raise any of the abc errors about unimplemented methods. class ActorBase(gevent.Greenlet): __metaclass__ = abc.ABCMeta @abc.abstractmethod def foo(self): print "foo" class ActorBaseTest(ActorBase): def bar(self): print "bar" abt = ActorBaseTest() # no errors! If I

Can python abstract base classes inherit from C extensions?

你离开我真会死。 提交于 2021-02-06 16:26:53
问题 It seems as if that when I have an abstract base class that inherits from gevent.Greenlet (which inherits from the C extension module greenlet: https://github.com/python-greenlet/greenlet) then classes that implement it do not raise any of the abc errors about unimplemented methods. class ActorBase(gevent.Greenlet): __metaclass__ = abc.ABCMeta @abc.abstractmethod def foo(self): print "foo" class ActorBaseTest(ActorBase): def bar(self): print "bar" abt = ActorBaseTest() # no errors! If I

Can python abstract base classes inherit from C extensions?

心不动则不痛 提交于 2021-02-06 16:26:47
问题 It seems as if that when I have an abstract base class that inherits from gevent.Greenlet (which inherits from the C extension module greenlet: https://github.com/python-greenlet/greenlet) then classes that implement it do not raise any of the abc errors about unimplemented methods. class ActorBase(gevent.Greenlet): __metaclass__ = abc.ABCMeta @abc.abstractmethod def foo(self): print "foo" class ActorBaseTest(ActorBase): def bar(self): print "bar" abt = ActorBaseTest() # no errors! If I

Passing a multiprocessing queue/dictionary/etc.. to green threads

落花浮王杯 提交于 2020-04-06 03:31:55
问题 Is it safe to pass a multiprocessing object (queue, dictionary, etc...) to multiple gevent threads? Since they're not actually running concurrently, I don't think there's a problem. However, I know that gevent isn't supposed to be specifically compatible with multiprocessing. 回答1: The benefits would likely be lost, standard threaded queue implements locks where a green thread would likely be slowed down. Thankfully, gevent often has its own but similar constructs. Check out gevent.queue 回答2:

Passing a multiprocessing queue/dictionary/etc.. to green threads

别来无恙 提交于 2020-04-06 03:30:07
问题 Is it safe to pass a multiprocessing object (queue, dictionary, etc...) to multiple gevent threads? Since they're not actually running concurrently, I don't think there's a problem. However, I know that gevent isn't supposed to be specifically compatible with multiprocessing. 回答1: The benefits would likely be lost, standard threaded queue implements locks where a green thread would likely be slowed down. Thankfully, gevent often has its own but similar constructs. Check out gevent.queue 回答2:

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

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-06 03:16:10
问题 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

Stackless in PyPy and PyPy + greenlet - differences

爷,独闯天下 提交于 2019-12-31 10:43:23
问题 New version of PyPy ships with integrated Stackless . As far as I know the bundled Stackless is not the same as the origin Stackless from 2001 with continuations. So mainly it is the green threads framework with dispatcher. Greenlet is a spin-of Stackless which provides the Stackless green threads functionality as an extension module. Is there any benefit from using "native" Stackless from PyPy than PyPy + greenlet + some dispatcher (eg: gevent )? Or the problem is that i can't use those