我使用python脚本在后端进行一些计算。该过程的工作方式如下:
我通过单击应用程序中的某些项来创建变量列表
该列表被发送到python脚本,并向后发送回json
基于该json文件,我显示一个表格
然后增加了变量列表,我可以再次执行此操作
但这是问题所在,当我在c9.io上本地运行时,可以说我将c9.io的地址提供给某人,然后当该人单击变量以添加到该列表时,他将其添加与我的清单相同当使用来自不同IP或其他名称的应用程序时,没有其他人的单独列表,因此它会造成混乱,因为当我发送到python脚本时,我得到的json文件的结果是我不想要的,但是其他人却得到了。
但是后来我打算将其托管在heroku上,我想知道它是否会以不同的方式工作,所以当有人从那里使用该应用程序时,他将获得自己的变量列表,并且不会被使用此程序的每个人共享与某人同时。还是有某种方法可以做到这一点?
这是应用程序的后端代码: 首先,这是用于将项目添加到列表中的代码,这就是问题所在,因为任何人同时执行此操作都会将其添加到同一列表中
var jsondata = ""
var thelist =[]
app.get("/show/:id", function (req, res) {
var id = req.params.id;
thelist.push(id)
console.log(thelist);
res.redirect('/')
});
然后剩下的(以便运行脚本并清空列表)
app.get("/run", function(req, res) {
var pyshell = new PythonShell('script.py');
pyshell.send(JSON.stringify(thelist))
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
jsondata += message
});
// end the input stream and allow the process to exit
pyshell.end(function (err) {
if (err){
throw err;
};
console.log(jsondata);
});
thelist = []
});
app.get('/data', function(req, res) {
if (jsondata == "") {
res.redirect('/')
} else {
//viewname can include or omit the filename extension
res.render("data", {data: JSON.parse(jsondata)} )
jsondata = ""}
});
因此,我认为我需要对这两个变量jsondata
和thelist
进行某种方式的编码,以使其对于每个唯一用户都是独立的(例如,从不同位置访问应用程序时,因此该应用将作为访问它的每个用户的单独会话运行(但也无需注册))