最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

关闭js(电子+烧瓶)上的PythonShell

IT培训 admin 3浏览 0评论

关闭js(电子+烧瓶)上的PythonShell

我已经在Google周围搜索,但是我找不到合适的答案,我不得不说我是NodeJS和electronic的新手:我的问题是我已使用Python-Shell将我的电子应用与烧瓶连接起来,但是当我关闭我的应用程序,即使关闭终端,烧瓶仍在后台运行。

这是我将应用程序连接到烧瓶的方式:

var pyshell =  require('python-shell');

  pyshell.PythonShell.run('engine.py',  function  (err, results)  {
    if  (err)  console.log(err);
  });

有什么方法可以“撤消”(关闭,退出,杀死)pyshell?我已经尝试过了,但是没有用:

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    pyshell.kill('engine.py'); // <-- I'm guessing here
    app.quit()
  }

这是完整的代码,很短,可能对识别问题很有用:

const {app, BrowserWindow} = require('electron')

function createWindow () {
  window = new BrowserWindow({width: 800, height: 600})
  window.loadFile('index.html')

  var pyshell =  require('python-shell');

  pyshell.PythonShell.run('engine.py',  function  (err, results)  {
    if  (err)  console.log(err);
  });
}

app.on('ready', createWindow)
app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    pyshell.kill('engine.py'); // <-- I'm guessing here
    app.quit()
  }
})
回答如下:

关闭js(电子+烧瓶)上的PythonShell

我已经在Google周围搜索,但是我找不到合适的答案,我不得不说我是NodeJS和electronic的新手:我的问题是我已使用Python-Shell将我的电子应用与烧瓶连接起来,但是当我关闭我的应用程序,即使关闭终端,烧瓶仍在后台运行。

这是我将应用程序连接到烧瓶的方式:

var pyshell =  require('python-shell');

  pyshell.PythonShell.run('engine.py',  function  (err, results)  {
    if  (err)  console.log(err);
  });

有什么方法可以“撤消”(关闭,退出,杀死)pyshell?我已经尝试过了,但是没有用:

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    pyshell.kill('engine.py'); // <-- I'm guessing here
    app.quit()
  }

这是完整的代码,很短,可能对识别问题很有用:

const {app, BrowserWindow} = require('electron')

function createWindow () {
  window = new BrowserWindow({width: 800, height: 600})
  window.loadFile('index.html')

  var pyshell =  require('python-shell');

  pyshell.PythonShell.run('engine.py',  function  (err, results)  {
    if  (err)  console.log(err);
  });
}

app.on('ready', createWindow)
app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    pyshell.kill('engine.py'); // <-- I'm guessing here
    app.quit()
  }
})
回答如下:
发布评论

评论列表 (0)

  1. 暂无评论