Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Modifying an object in a fork

by 1nickt (Canon)
on Mar 11, 2018 at 23:45 UTC ( [id://1210694]=note: print w/replies, xml ) Need Help??


in reply to Modifying an object in a fork

It's trivial using the mighty MCE::Shared by marioroy, two extra lines:

package MyClass { use Moose; has foo => ( is => 'rw', default => 'bar' ); }; package main { use strict; use warnings; use feature 'say'; use MCE::Shared; my $obj = MCE::Shared->share({ module => 'MyClass' }); say 'Before forking: ' . $obj->foo; my $pid = fork; if ( $pid == 0 ) { $obj->foo('baz'); exit; } else { waitpid $pid, 0; } say 'After forking: ' . $obj->foo; };
Output:
$ perl 1210687.pl Before forking: bar After forking: baz
For details see the documentation on sharing objects between processes with MCE::Shared.

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Modifying an object in a fork
by marioroy (Prior) on Apr 29, 2018 at 11:03 UTC

    Hi 1nickt,

    It's trivial using the mighty MCE::Shared ...

    Also, see the logger and Tie::File MCE::Shared demonstrations. The object class, like in your demo, is constructed under the shared-manager process where it lives. How it works is that any interaction with the object is then possible via the OO interface only.

    Regards, Mario

Re^2: Modifying an object in a fork
by nysus (Parson) on Mar 14, 2018 at 18:05 UTC

    Thanks, hadn't heard of that module before.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210694]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-25 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found