-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
boa: support running Python code in non-blocking way (#602)
It uses the Node.js worker_threads to start new thread to run Python functions. Note that, we share the same Python interrupter.
- Loading branch information
Showing
16 changed files
with
1,581 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { Python } = require('bindings')('boa'); | ||
|
||
// read the conda path from the .CONDA_INSTALL_DIR | ||
// eslint-disable-next-line no-sync | ||
const condaPath = fs.readFileSync(path.join(__dirname, '../.CONDA_INSTALL_DIR'), 'utf8'); | ||
if (!process.env.PYTHONHOME) { | ||
process.env.PYTHONHOME = condaPath; | ||
} | ||
|
||
// create the global-scoped instance | ||
let pyInst = global.__pipcook_boa_pyinst__; | ||
if (pyInst == null) { | ||
pyInst = new Python(process.argv.slice(1)); | ||
global.__pipcook_boa_pyinst__ = pyInst; | ||
} | ||
|
||
// FIXME(Yorkie): move to costa or daemon? | ||
const globals = pyInst.globals(); | ||
const builtins = pyInst.builtins(); | ||
|
||
module.exports = { | ||
condaPath, | ||
pyInst, | ||
globals, | ||
builtins, | ||
}; |
Oops, something went wrong.