http://qs321.pair.com?node_id=11133139


in reply to Re: Inline::Java with MCE::Hobo
in thread Inline::Java with MCE::Hobo

I could not make the require work. First, I removed the "use SexCoder" from the top of my script. Then I added this:

MCE::Hobo->init(on_start => sub { require SexCoder; });
The error message I got was:
Hobo 30016 terminated abnormally: reason Can't locate object method "n +ew" via package "SexCoder" (perhaps you forgot to load "SexCoder"?) a +t ./convert.mce line 721, <__ANONIO__> line 24.

So, the SexCoder did not load. I then tried removing the Hobo->init and placing "use SexCoder" inside my worker sub {}. That was no different than my original code. I had exactly the same issue, where some workers were able to get results from the service and others were not. That really confuses me. I think you are on the right track, though. There must be something odd in my SexCoder package that I'm not seeing. See my reply to cavac above for the complete code to that package. Maybe you can see something?

I have one more tidbit for everyone helping me. The code works if $num_workers = 1 (simulating single-threaded code). That's why I suspect an issue with Inline::Java or with the rtsClient itself. I just can't fathom why if each is running in its own process.

Replies are listed 'Best First'.
Re^3: Inline::Java with MCE::Hobo
by Anonymous Monk on Jul 24, 2021 at 05:32 UTC

    Greetings eraskin,

    Have you tried importing SexCoder inside the input_task Hobo routine. This is where to load the class uniquely per worker child.

    sub input_task { require SexCoder; SexCoder->import(); # THIS CALLS JAVA TO CREATE THE CONNECTION TO DATA SERVICES my $sexcoder = SexCoder->new("$ds_server", 4000); ... }

      Kind reminder: Remember to comment out SexCoder at the top of the script to ensure the class is loaded by each Hobo worker individually.

      my $num_workers = 5; # use SexCoder; use MCE::Hobo; use MCE::Shared; ...