ReferenceError: weakly-referenced object no longer exists Python kafka

Posted 编程人生改变命运

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ReferenceError: weakly-referenced object no longer exists Python kafka相关的知识,希望对你有一定的参考价值。

Python存入kafka报错,ReferenceError: weakly-referenced object no longer exists。

Exception in thread 14: pykafka.OwnedBroker.queue_reader for broker 101:
Traceback (most recent call last):
  File "C:Python27lib	hreading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:Python27lib	hreading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:Python27libsite-packagespykafkaproducer.py", line 624, in queue_reader
    self.producer._worker_exception = sys.exc_info()
ReferenceError: weakly-referenced object no longer exists

  解决办法是加入   producer.stop()

 

完整代码是:

# kafka 连接
KAFKA_IP_PORT = 192.168.1.13:9082
# KAFKA_IP_PORT = ‘192.168.0.23:9082‘
KAFKA_TOPIC_NAME = test-topic


def kafka_save(data):
    print "获得的信息是:",data

    client = KafkaClient(hosts=KAFKA_IP_PORT)
    producer = client.topics[KAFKA_TOPIC_NAME.encode(encoding="UTF-8")].get_producer()
    data_str = str(data)
    producer.produce(data_str.encode(encoding=UTF-8))
   producer.stop()
   print "推送到kafka成功"

其中 data是推送到kafka中的数据

以上是关于ReferenceError: weakly-referenced object no longer exists Python kafka的主要内容,如果未能解决你的问题,请参考以下文章

ReferenceError:未定义 DartObject

ReferenceError:未定义提取

Rails:ReferenceError:未定义谷歌

ReferenceError:变量未定义

JavaScript Uncaught ReferenceError: jQuery is not defined;未捕获的 ReferenceError:$ 未定义 [重复]

ReferenceError:找不到变量