Python的ThreadPoolExecutor.submit()在Windows和Linux中的工作方式不同

时间:2019-08-30 12:11:02

标签: python-3.x linux apache-kafka submit threadpoolexecutor

我正在尝试使用以下脚本接收kafka消息。消息是在Windows中接收的,但是在Linux系统中却没有。另外,当在以下代码中调用run函数时,Windows中的python控制台将连续不断地打印“线程池内”,而linux中的python控制台仅打印“线程池内”一次,然后代码挂起(或至少不挂起)在控制台中提供任何内容)

def run(self):
    print('Running KafkaThread. . . ')
    try:
        while True:
            print("Inside the threadpool")
            for consumer, callback in consumers:
                thread_pool.submit(Handler.consumer_request, consumer, callback)
            time.sleep(5)
    except Exception:
        logger.error(f'Error occurred in {__name__} : {sys.exc_info()[0]}', exc_info=True)
        raise


def consumer_request(consumer, callback):
    key, value = None, None
    try:
        for msg in consumer:
            key = msg.key if msg.key is None else msg.key.decode('utf-8')
            value = msg.value
            callback.on_success(key, value)
    except Exception as e:
        logger.error(f'ERROR occurred while consuming from kafka {sys.exc_info()[0]}', exc_info=True)
        callback.on_error(key, e)

0 个答案:

没有答案