我要制作一个Rest API,它的工作方式如下:
我想到import subprocess
import sys
from PyQt4.QtCore import QObject, QThread, pyqtSignal
from PyQt4.QtGui import QDialog, QTextEdit, QVBoxLayout, QPushButton, QApplication
class MyDialog(QDialog):
def __init__(self):
super(MyDialog, self).__init__()
self.ui_lay = QVBoxLayout()
self.setLayout(self.ui_lay)
self.ui_txt = QTextEdit(self)
self.ui_lay.addWidget(self.ui_txt)
self.ui_btn = QPushButton('Ping', self)
self.ui_lay.addWidget(self.ui_btn)
self.thread = MyThread(self)
self.thread.line_printed.connect(self.handle_line)
self.ui_btn.clicked.connect(self.run_thread)
def run_thread(self):
self.thread.start_command('ping google.com')
def handle_line(self, line):
cursor = self.ui_txt.textCursor()
cursor.movePosition(cursor.End)
cursor.insertText(line)
self.ui_txt.ensureCursorVisible()
class MyThread(QThread):
line_printed = pyqtSignal(str)
def __init__(self, parent):
super(MyThread, self).__init__(parent)
self.cmd = None
def start_command(self, cmd):
self.cmd = cmd
self.start()
def run(self):
if self.cmd:
popen = subprocess.Popen(self.cmd, stdout=subprocess.PIPE, shell=True)
lines_iterator = iter(popen.stdout.readline, b"")
for line in lines_iterator:
self.line_printed.emit(line)
if __name__ == '__main__':
app = QApplication(sys.argv)
dlg = MyDialog()
dlg.show()
app.exec_()
,但我如何在标题上存储一些信息?还有另一种方式吗?
答案 0 :(得分:0)
如果令牌的有效期太长。
您可以使用redis
保存与令牌对应的用户信息。
像这样的东西。
此外,您可以使用令牌简单地查询以获取用户对象。
{token : {user Object}}
您可以编写删除令牌脚本来删除过期的令牌。