Problem with Storable on Windows

Problem with Storable on Windows

am 04.07.2005 13:20:08 von dfg778

I'm trying to use Storable in conjunction with IPC::Open3 in order to
send complex data structures between the parent and child processes.
Unfortunately, although this seems to work a treat under Linux (Fedora
Core 4), it doesn't seem to work on Windows, returning the following
message:

Magic number checking on storable file failed at blib\lib\Storable.pm
(autosplit into blib\lib\auto\Storable\fd_retrieve.al) line 323, at
D:\Data\Perl\DBAsyncWorker.pl line 13

Here's my code:

Caller:

#!/usr/bin/perl

use Storable qw(nstore_fd freeze) ;
use IPC::Open3 ;
use IO::Handle ;

autoflush STDOUT ;
print "Caller starting\n" ;
$Storable::Deparse = 1 ;
%parms = ( data_source => 'DBI:Pg:dbname=matthew',
userid => 'matthew',
password => 'vishnu',
statement => 'select * from test_table') ;
$command = 'DBAsyncWorker.pl' ;
print "About to call worker\n" ;
$pid = open3($wtr,$rdr,$err,$command) ;
# This line added for Windows
binmode $wtr ;
print "Worker started\n" ;

while(($line = <$rdr>) !~ 'End') {
if ($line =~ /START/) {
print "Received start command\n" ;
nstore_fd \%parms, $wtr ;
}
else {
print $line ;
}
}


Worker:

#!/usr/bin/perl

use DBI ;
use Data::Dumper ;
use IO::Handle ;
use Storable qw(fd_retrieve thaw) ;

$Storable::Eval = 1 ;

autoflush STDOUT ;
# This line added for Windows
binmode STDIN ;
print "START\n";
$parm_ref = fd_retrieve(\*STDIN) ;
print "Retrieved parm reference\n",Dumper($parm_ref) ;
print "Userid = ",$parm_ref->{userid},"\n" ;
print "Password = ",$parm_ref->{password},"\n" ;
print "Statement = ",$parm_ref->{statement},"\n" ;
print "End\n" ;

Here's what I've tried, without luck:

* Using store_fd instead of nstore_fd
* Using freeze in the caller, printing the frozen value to $wtr, and
then reading it on the worker using sysread and using thaw

Freeze'ing and thaw'ing within a single program works fine, it's just
when I send it over a file handle that the problem occurs.

Does anybody have any ideas ?

Re: Problem with Storable on Windows

am 05.07.2005 10:56:13 von Thomas Kratz

Matthew Keene wrote:
> I'm trying to use Storable in conjunction with IPC::Open3 in order to
> send complex data structures between the parent and child processes.
> Unfortunately, although this seems to work a treat under Linux (Fedora
> Core 4), it doesn't seem to work on Windows, returning the following
> message:
>
> Magic number checking on storable file failed at blib\lib\Storable.pm
> (autosplit into blib\lib\auto\Storable\fd_retrieve.al) line 323, at
> D:\Data\Perl\DBAsyncWorker.pl line 13

[code snipped]

You don't have a problem with Storable, but with IPC::Open3. I modified
your code a bit and found that the data the caller sent never made it to
the client. So you try to thaw an empty string, which Storable complains
about. Reading from the pipe in the worker never succeeds. I'm not an
expert, but googling for problems with IPC::Open3 on Windows will show a
few threads. If you don't find a solution there, I would suggest doing the
communication over sockets. At least that works (it does for me).
This could perhaps all be related to select working only on sockets under
Windows.

Thomas

--
$/=$,,$_=,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~...... >r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k ^.-