网站无法通过rethinkdb和龙卷风实现

时间:2018-12-03 10:28:05

标签: python asynchronous tornado rethinkdb

大家好, 在编程和使用数据库方面,我是一个新手。尽管我试图解决问题,但是我自己在论坛中查找并附带了驱动程序的文档。 因此,我试图创建一个异步应用程序/网站,在该网站上,我保存在数据库(Rethinkdb)中的数据也可以显示在网站中(为此,我正在使用龙卷风)。事实是,数据随时间变化,因此网站应该每秒钟/毫秒/以任何方式自动更新(作为实时应用程序),这样就可以查看网站中的每个数据。这个想法不是每次都更改端口或在网站刷新时每次单击。 我实现的代码是下一个代码,之后是错误代码。

import rethinkdb as r
from tornado import ioloop, gen
from tornado.concurrent import Future, chain_future
import functools
import tornado.web

@gen.coroutine
def single_row(connection):
    # Wait for the connection to be ready
    connection = yield connection_future
    # Insert some data
    yield r.db('test').table('test2').insert([{"id": 4}, {"id": 4}, {"id": 5},{"id": 6}]).run(connection)
    # Print the first row in the table
    row = yield r.db('test').table('test2').get(0).run(connection)
    yield row

def print_feed(connection_future):
    connection = yield connection_future
    feed = yield r.db('test').table('table4').changes().run(connection)
    #while (yield feed.fetch_next()):
    while (yield feed.fetch_next()):
        item = yield feed.next()
        myMessage.NewSentence(number=item)

def make_app():
    return tornado.web.Application([(r"/", MainHandler),])

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write(myMessage.message)

class MyMessage():
    def __init__(self):
        self.message = "Hello world, the number is: 16"

    def NewSentence(self, number):
        self.message = "Hello world, the number is: " + str(number)

if __name__ == "__main__":
    r.set_loop_type("tornado")
    connection = r.connect(host='localhost', port=28015)

    myMessage = MyMessage()

    print_feed(connection)

    #myMessage.NewSentence(35)

    app = make_app()
    app.listen(8888)

    ioloop.IOLoop.current().add_callback(print_feed(), connection)

现在出现错误:

runfile('/home/advaptive-balancing/Documents/um/rethinkdb/dasbeste.py', wdir='/home/advaptive-balancing/Documents/um/rethinkdb')
Reloaded modules: __mp_main__
Traceback (most recent call last):

  File "<ipython-input-2-a45fa54bbd25>", line 1, in <module>
    runfile('/home/advaptive-balancing/Documents/um/rethinkdb/dasbeste.py', wdir='/home/advaptive-balancing/Documents/um/rethinkdb')

  File "/home/advaptive-balancing/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 668, in runfile
    execfile(filename, namespace)

  File "/home/advaptive-balancing/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/home/advaptive-balancing/Documents/um/rethinkdb/dasbeste.py", line 57, in <module>
    app.listen(8888)

  File "/home/advaptive-balancing/anaconda3/lib/python3.7/site-packages/tornado/web.py", line 1944, in listen
    server.listen(port, address)

  File "/home/advaptive-balancing/anaconda3/lib/python3.7/site-packages/tornado/tcpserver.py", line 142, in listen
    sockets = bind_sockets(port, address=address)

  File "/home/advaptive-balancing/anaconda3/lib/python3.7/site-packages/tornado/netutil.py", line 197, in bind_sockets
    sock.bind(sockaddr)

OSError: [Errno 98] Address already in use

非常感谢您的帮助,如果有人可以帮助我,那就太好了。 亲切的问候 Uriel

0 个答案:

没有答案