Python`在atexit._run_exitfuncs`中出错

时间:2017-07-12 08:48:33

标签: python python-3.x apache-kafka kafka-consumer-api kafka-python

我正在尝试使用kafka MultiProcessConsumer,但我遇到了以下错误。似乎错误与python中的多线程有关

这是我正在使用的代码。

simple.py

from kafka import SimpleProducer, SimpleClient, SimpleConsumer, MultiProcessConsumer

# To consume messages
client = SimpleClient('localhost:9092')
consumer = MultiProcessConsumer(client, "my-group", "testing_topic", num_procs=3)
for message in consumer:
    # message is raw byte string -- decode if necessary!
    # e.g., for unicode: `message.decode('utf-8')`
    print(message)

client.close()

在代码上运行时出错。

$ python simple.py 
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/var/users/ec2-user/.pyenv/versions/3.6.0/lib/python3.6/multiprocessing/managers.py", line 749, in _callmethod
    conn = self._tls.connection
AttributeError: 'ForkAwareLocal' object has no attribute 'connection'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/users/ec2-user/.pyenv/versions/3.6.0/lib/python3.6/multiprocessing/connection.py", line 614, in SocketClient
    s.connect(address)
FileNotFoundError: [Errno 2] No such file or directory

0 个答案:

没有答案