我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用gevent.core()。
def start(self, sender, **kwargs): self.vip.pubsub.subscribe(peer = 'pubsub', prefix = 'fncs/input/', #prefix = '', callback = self.onmessage).get(timeout=5) #Register with FNCS cfg = "name = {0[name]}\ntime_delta = {0[time_delta]}\nbroker = {0[broker]}\n".format(self.fncs_zpl) if 'values' in self.fncs_zpl.keys(): cfg += "values" for x in self.fncs_zpl['values'].keys(): cfg += "\n {0}\n topic = {1[topic]}\n defualt = {1[default]}\n type = {1[type]}\n list = {1[list]}".format(x,self.fncs_zpl['values'][x]) fncs.initialize(cfg) if not fncs.is_initialized(): raise RuntimeError("FNCS connection failed!") self.publish_heartbeat() print(self.heartbeat_period) self.core.periodic(self.heartbeat_period, self.publish_heartbeat)
def __setup_events(self): self.__readable = AsyncResult() self.__writable = AsyncResult() self.__readable.set() self.__writable.set() try: self._state_event = get_hub().loop.io(self.getsockopt(zmq.FD), 1) # read state watcher self._state_event.start(self.__state_changed) except AttributeError: # for gevent<1.0 compatibility from gevent.core import read_event self._state_event = read_event(self.getsockopt(zmq.FD), self.__state_changed, persist=True)
def init_process(self): # monkey patch here self.patch() # reinit the hub import gevent.core gevent.core.reinit() #gevent 0.13 and older doesn't reinitialize dns for us after forking #here's the workaround gevent.core.dns_shutdown(fail_requests=1) gevent.core.dns_init() super(GeventWorker, self).init_process()