Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fridgerator/pynode",
"version": "0.5.1",
"description": "Node <-> Python interopability",
"version": "0.5.2",
"description": "Node <-> Python interoperability",
"main": "build/Release/PyNode",
"author": "Nick Franken <[email protected]>",
"license": "MIT",
Expand Down
8 changes: 4 additions & 4 deletions src/pynode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Napi::Value StartInterpreter(const Napi::CallbackInfo &info) {
mbstowcs(&path[0], pathString.c_str(), pathString.length());
Py_SetPath(path.c_str());
}

PyImport_AppendInittab("pynode", &PyInit_jswrapper);

int isInitialized = Py_IsInitialized();
Expand All @@ -31,6 +31,9 @@ Napi::Value StartInterpreter(const Napi::CallbackInfo &info) {
if (threadsInitialized == 0)
PyEval_InitThreads();

/* Ensure GIL */
py_thread_context ctx;

/* Load PyNode's own module into Python. This makes WrappedJSObject instances
behave better (eg, having attributes) */
PyObject *pName;
Expand All @@ -43,9 +46,6 @@ Napi::Value StartInterpreter(const Napi::CallbackInfo &info) {
.ThrowAsJavaScriptException();
}

/* Release the GIL. The other entry points back into Python re-acquire it */
PyEval_SaveThread();

return env.Null();
}

Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ describe('nodePython', () => {
})
})

describe('duplicate startInterpreter', () => {
it('No error should happen when calling startInterpreter again', () => {
nodePython.startInterpreter();
});
})

// describe('stopInterpreter', () => {
// it('should stop the interpreter', () => {
// nodePython.stopInterpreter()
Expand Down