Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opencv4nodejs inside worker threads #555

Open
diegonc opened this issue May 10, 2019 · 6 comments
Open

opencv4nodejs inside worker threads #555

diegonc opened this issue May 10, 2019 · 6 comments

Comments

@diegonc
Copy link

diegonc commented May 10, 2019

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
@diegonc
Copy link
Author

diegonc commented May 10, 2019

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 :(

@TWhidden
Copy link

TWhidden commented Aug 4, 2019

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.

@suren-atoyan
Copy link

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!

@moeiscool
Copy link

moeiscool commented Aug 16, 2020

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 :)

@kinsi55
Copy link

kinsi55 commented Sep 19, 2020

No updates yet?

@jdmg94
Copy link

jdmg94 commented Sep 13, 2022

I'm also having this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants