diff --git a/server/package-lock.json b/server/package-lock.json index 2018fe0b6..c2899bd38 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/server", - "version": "0.94.32", + "version": "0.94.33", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/server", - "version": "0.94.32", + "version": "0.94.33", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/server/src/plugin/runtime/python-worker.ts b/server/src/plugin/runtime/python-worker.ts index 789a87b14..6da7fa980 100644 --- a/server/src/plugin/runtime/python-worker.ts +++ b/server/src/plugin/runtime/python-worker.ts @@ -7,6 +7,7 @@ import { PassThrough, Readable, Writable } from 'stream'; import { installScryptedServerRequirements, version as packagedPythonVersion } from '../../../bin/packaged-python'; import { RpcMessage, RpcPeer } from "../../rpc"; import { createRpcDuplexSerializer } from '../../rpc-serializer'; +import { getPluginVolume } from '../plugin-volume'; import { ChildProcessWorker } from "./child-process-worker"; import { RuntimeWorkerOptions } from "./runtime-worker"; @@ -23,8 +24,6 @@ export class PythonRuntimeWorker extends ChildProcessWorker { } } - static pythonInstalls = new Map>(); - serializer: ReturnType; peerin: Writable; peerout: Readable; @@ -128,30 +127,32 @@ export class PythonRuntimeWorker extends ChildProcessWorker { (this.worker.stdio[4] as Readable).pipe(peerout); }; - const py = new PortablePython(pluginPythonVersion); + const pyVersion = require('py/package.json').version; + const pyPath = path.join(getPluginVolume(pluginId), 'py'); + const portableInstallPath = path.join(pyPath, pyVersion); + + const py = new PortablePython(pluginPythonVersion, portableInstallPath); if (fs.existsSync(py.executablePath)) { pythonPath = py.executablePath; finishSetup(); } else { - this.pythonInstallationComplete = false; - let install = PythonRuntimeWorker.pythonInstalls.get(pluginPythonVersion); - if (!install) { - install = installScryptedServerRequirements(pluginPythonVersion); - install.catch(() => { }); - PythonRuntimeWorker.pythonInstalls.set(pluginPythonVersion, install); - } - - install.then(executablePath => { - pythonPath = executablePath; - finishSetup(); - }) - .catch(() => { + (async () => { + try { + this.pythonInstallationComplete = false; + await fs.promises.rm(pyPath, { recursive: true, force: true }).catch(() => { }); + pythonPath = await installScryptedServerRequirements(pluginPythonVersion, portableInstallPath); + finishSetup(); + } + catch (e) { process.nextTick(() => { this.emit('error', new Error('Failed to install portable python.')); - }) - }) - .finally(() => this.pythonInstallationComplete = true); + }); + } + finally { + this.pythonInstallationComplete = true + } + })(); } } else {