每当我尝试此代码和文件更新时,我都会在命令行上收到以下消息:
SystemError:您只能从主可调用对象调用 uwsgi api 函数
任何人都可以向我解释如何正确地做到这一点吗?
谢谢!
#!/usr/bin/env python
import logging
import time
from flask import Flask, render_template
from flask.ext.uwsgi_websocket import WebSocket
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
logging.basicConfig(level=logging.ERROR)
app = Flask(__name__)
ws = WebSocket(app)
class MyEventHandler(FileSystemEventHandler):
def __init__(self, observer, filename, ws):
self.observer = observer
self.filename = filename
self.ws = ws
def on_modified(self, event):
self.ws.send('The file is updated!')
@ws.route('/')
def websocket_server(ws):
path = '/var/lib/omniwallet/addr/'
observer = Observer()
while True:
address = ws.receive()
if address is not None:
filename = address + '.json'
event_handler = MyEventHandler(observer, filename, ws)
observer.schedule(event_handler, path, recursive=False)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
else: return
if __name__ == '__main__':
app.run(debug=True, threads=16)