Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Modifying an object in a fork

by 1nickt (Monsignor)
on Mar 11, 2018 at 23:45 UTC ( #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 nysus (Priest) 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
Node Status?
node history
Node Type: note [id://1210694]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-04-20 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?