Skip to content

Commit

Permalink
Add option to configure call timeout (REQ_TIMEOUT) from env var (#90)
Browse files Browse the repository at this point in the history
* allow setting REQ_TIMEOUT from env var

* allow setting REQ_TIMEOUT from env var

* Add REQ_TIMEOUT usage to README.md
  • Loading branch information
jc-roman committed Aug 8, 2023
1 parent 1671cbf commit 95ad451
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,5 @@ for await (const file of files) {
* On the bridge to call JavaScript from Python, due to the limiatations of Python and cross-platform IPC, we currently communicate over standard error which means that JSON output in JS standard error can interfere with the bridge. The same issue exists on Windows with python. You are however very unlikely to have issues with this.

* You can set the Node.js/Python binary paths by setting the `NODE_BIN` or `PYTHON_BIN` enviornment variables before importing the library. Otherwise, the `node` and `python3` or `python` binaries will be called relative to your PATH enviornment variable.

* Function calls will timeout after 100000 ms and throw a `BridgeException` error. That default value can be overridden by defining the new value of `REQ_TIMEOUT` in an environment variable.
3 changes: 2 additions & 1 deletion src/javascript/js/pyi.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const util = require('util')
if (typeof performance === 'undefined') var { performance } = require('perf_hooks')
const log = () => { }
const errors = require('./errors')
const REQ_TIMEOUT = 100000
// use REQ_TIMEOUT env var value if parseable as integer, otherwise default to 100000 (ms)
const REQ_TIMEOUT = parseInt(process.env.REQ_TIMEOUT) || 100000

class BridgeException extends Error {
constructor (...a) {
Expand Down
3 changes: 2 additions & 1 deletion src/pythonia/Bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const { JSBridge } = require('./jsi')
const errors = require('./errors')
const log = process.env.DEBUG ? console.debug : () => {}
// const log = console.log
const REQ_TIMEOUT = 100000
// use REQ_TIMEOUT env var value if parseable as integer, otherwise default to 100000 (ms)
const REQ_TIMEOUT = parseInt(process.env.REQ_TIMEOUT) || 100000

class BridgeException extends Error {
constructor (...a) {
Expand Down

0 comments on commit 95ad451

Please sign in to comment.