def __check_monkey_patch(self): if self._concurrent_mode == 2: check_gevent_monkey_patch() elif self._concurrent_mode == 3: check_evenlet_monkey_patch() else: check_not_monkey()
def build_pool(self): if self.consumer._threadpool: return self.consumer._threadpool pool_type = None # 是按照ThreadpoolExecutor写的三个鸭子类,公有方法名和功能写成完全一致,可以互相替换。 if self._concurrent_mode == 1: pool_type = CustomThreadPoolExecutor # pool_type = BoundedThreadPoolExecutor check_not_monkey() elif self._concurrent_mode == 2: pool_type = GeventPoolExecutor check_gevent_monkey_patch() elif self._concurrent_mode == 3: pool_type = CustomEventletPoolExecutor check_evenlet_monkey_patch() elif self._concurrent_mode == 4: pool_type = AsyncPoolExecutor if self._concurrent_mode == 4: self.consumer._threadpool = self.consumer._specify_concurrent_pool if self.consumer._specify_concurrent_pool else pool_type( self.consumer._concurrent_num, loop=self.consumer._specify_async_loop) else: self.consumer._threadpool = self.consumer._specify_concurrent_pool if self.consumer._specify_concurrent_pool else pool_type( self.consumer._concurrent_num) return self.consumer._threadpool
def build_pool(self): if self.consumer._threadpool: return self.consumer._threadpool pool_type = None # 是按照ThreadpoolExecutor写的三个鸭子类,公有方法名和功能写成完全一致,可以互相替换。 if self._concurrent_mode == 1: pool_type = CustomThreadPoolExecutor # pool_type = BoundedThreadPoolExecutor check_not_monkey() elif self._concurrent_mode == 2: pool_type = GeventPoolExecutor check_gevent_monkey_patch() elif self._concurrent_mode == 3: pool_type = CustomEventletPoolExecutor check_evenlet_monkey_patch() self.consumer._threadpool = self.consumer._specify_threadpool if self.consumer._specify_threadpool else pool_type(self.consumer._threads_num + 1) # 单独加一个检测消息数量和心跳的线程 return self.consumer._threadpool