javascript - 使用 NPM Python Shell 回调 Electron
问题描述
所以这是我的代码,我正在使用 python sheel 来执行一个读取 RFID 标签的 python 脚本。python脚本工作正常,但我的问题是我想在python脚本执行后(当我将标签放在RFID阅读器上时)控制台.log(“测试”),而不是控制台首先记录“测试”,然后然后执行python脚本。有什么办法可以解决这个问题,回调什么的?
function getDadosPulseira(){
var {PythonShell} = require('python-shell')
var path = require('path')
var options = {
scriptPath: path.join(__dirname, '../_engine/')//,
}
var readrfid = new PythonShell('readtag.py', options)
readrfid.on("message", function(message) {
swal({
title: "Pulseira!",
text: message,
icon: "success",
timer: 3000
});
console.log(message);
})
console.log("testing");
}
解决方案
async function getDadosPulseira() {
var {PythonShell} = require('python-shell')
var path = require('path')
var options = {
scriptPath: path.join(__dirname, '../_engine/')//,
}
var readrfid = new PythonShell('readtag.py', options)
readrfid.on("message", function(message) {
swal({
title: "Pulseira!",
text: message,
icon: "success",
timer: 3000
});
console.log(message);
})
readrfid.end(function (err) {
console.log("testing");
});
}
推荐阅读
- node.js - 如何让 REST 与 OpenFaaS 协同工作?
- java - 底层 Http2(H2) 客户端和服务器实现
- asp.net-mvc - 审核更改日志未记录不是创建时的主键
- reactjs - video.play() 后我听到声音,但视频不工作
- javascript - 使用 setState 提交后清除表单输入
- r - 跨列应用函数
- python - Discord.py 列出机器人所在的所有服务器名称
- python - 在 Python 中使用多个 for 循环 Using Beautiful Soup
- javascript - 由于未定义的属性,循环内的滚动功能不起作用
- docker - 无法从 Docker 容器内请求 ActiveMQ 端口 8161:没有到主机的路由