opencv4nodejs
opencv4nodejs copied to clipboard
opencv4nodejs inside worker threads
Using opencv4nodejs inside a worker thread causes the error message Module did not self-register.
To make it work the module must be context aware as described here.
To reproduce the little snippet below (which is based on this bug report) can be used:
$ cat > a.js << EOF
const cv = require('opencv4nodejs');
const {Worker} = require('worker_threads');
new Worker(__filename);
EOF
$ node --experimental-worker a.js
Changing the module definition, as explained in the documentation, in opencv4nodejs.cc is not enough.
-NODE_MODULE(opencv4nodejs, init)
+NODE_MODULE_INIT() {
+ init(exports);
+}
as it will fail at runtime:
FATAL ERROR: HandleScope::HandleScope Entering the V8 API without proper locking in place
1: 0x8dc1c0 node::Abort() [node]
2: 0x8dc20c [node]
3: 0xad5e8a v8::Utils::ReportApiFailure(char const*, char const*) [node]
4: 0xad7122 v8::HandleScope::Initialize(v8::Isolate*) [node]
5: 0xb0462f v8::FunctionTemplate::GetFunction(v8::Local<v8::Context>) [node]
6: 0xb0494d v8::FunctionTemplate::GetFunction() [node]
7: 0x7f9b48600cb4 VideoCaptureBindings::ReadWorker::getReturnValue() [/home/diegonc/dev/nexitel/localdev/faces/node_modules/opencv4nodejs/build/Release/opencv4nodejs.node]
8: 0x7f9b485ffc19 VideoCapture::Read(Nan::FunctionCallbackInfo<v8::Value> const&) [/home/diegonc/dev/nexitel/localdev/faces/node_modules/opencv4nodejs/build/Release/opencv4nodejs.node]
9: 0x7f9b485fab5f [/home/diegonc/dev/nexitel/localdev/faces/node_modules/opencv4nodejs/build/Release/opencv4nodejs.node]
10: 0xb5e7cf [node]
11: 0xb5f339 v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [node]
12: 0xb7fadedbe1d
This seems to be a bigger change :(
Yea, having the same problem myself. Trying to offload some image processing outside my main loop and transfer the opencv image to another worker / core. Ran into the same thing as I am trying to implement this. I don't have time to work on the opencv4nodejs project, so giving a +1 vote for solutions here.
Hi, @justadudewhohacks. Any idea about this issue?
I also tried to use opencv4nodejs in a separate worker, but it failed with the same error. So, as I understood it should be context aware. Any idea?
Thank you!
i just started my "worker" script as a child process (spawn) and it seems to work fine now. I just use the stdin and stdout, parse the in and out as JSON so it behaves the same as the "native workers".
UPDATE : I made this module based on child_process.spawn https://www.npmjs.com/package/shinobi-worker enjoy :)
No updates yet?
I'm also having this issue