Py学习  »  MQ

对rabbitmq使用sqlalchemy

Morgan Allen • 4 年前 • 943 次点击  

我有一个运行在多个处理器上的webscraper,它可以写入sqlite数据库。由于sqlite不是用来处理并发写操作的,所以我想使用一个队列系统来处理多个输入,并且只向数据库中写入一个对象

我浏览了rabbitmq hello world示例,得到一个错误。

我的 send.py 文件:

from models import TestCan
from models import TestJobs

import pika

# init_db()

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()

channel.basic_publish(exchange='',
                      routing_key='hello',
                      body=TestCan('Test'))

这个 models.py 用文件 TestCan :

class TestCan(Base):
    __tablename__ = 'test_can'
    id = Column(Integer, primary_key=True)
    name = Column(String())


    def __init__(self, name=None):
        self.name = name

    def __repr__(self):
        return '<Name: %s>' % (self.name)

我得到这个错误:

TypeError: object of type 'TestCan' has no len()

那是什么意思?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43305
 
943 次点击  
文章 [ 1 ]  |  最新文章 4 年前