替换 gevent.spawn_link_exception

Replace gevent.spawn_link_exception

这段旧代码调用了 gevent.spawn_link_exception,它不再存在:

def start(self, checkpoint=None):
    for gl in self._greenlets:
        gl.kill()
    self.load_config()
    self._greenlets = [
        gevent.spawn_link_exception(self.periodic_checkpoint, 5) ]
    for master_uri in self._config:
        self._greenlets.append(
            gevent.spawn_link_exception(
                self.replicate, master_uri, checkpoint))

请帮助我更新此代码,使其适用于最新版本的 gevent。谢谢

您可以通过 Greenlet.link_exception 方法处理同样的事情。这是您修改后的示例:

  def start(self, checkpoint=None):
      for gl in self._greenlets:
          gl.kill()
      self.load_config()

      def exception_callback(greenlet):
          print "Exception happened in ", greenlet

      self._greenlets = [gevent.spawn(self.periodic_checkpoint, 5)]
      self._greenlets[-1].link_exception(exception_callback)

      for master_uri in self._config:
          self._greenlets.append(gevent.spawn(self.replicate, master_uri, checkpoint))
          self._greenlets[-1].link_exception(exception_callback)