Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Does IO::Select work? Anywhere?

by ikegami (Pope)
on Oct 21, 2012 at 08:48 UTC ( #1000184=note: print w/ replies, xml ) Need Help??


in reply to Does IO::Select work? Anywhere?

One-way comm:

use strict; use warnings; use IO::Select qw( ); use IPC::Open3 qw( open3 ); use Symbol qw( gensym ); sub launch { my ($id) = @_; open(local *TO_CHILD, '<', '/dev/null') or die $!; *TO_CHILD if 0; my $pid = open3( '<&TO_CHILD', my $from_child = gensym(), '>&STDERR', perl => ( -e => 'use Time::HiRes qw( sleep ); $|=1; for (1..rand +(10)+5) { sleep(0.100 + rand(100)/1000); print "a" }' ), ); return { id => $id, pid => $pid, pipe => $from_child, buf => '' }; } my %children = map { $_->{pipe} => $_ } map launch($_), 1..2; my $sel = IO::Select->new( map $_->{pipe}, values %children ); while ($sel->count) { for my $fh ($sel->can_read(0.050)) { my $child = $children{$fh}; our $buf; local *buf = \( $child->{buf} ); my $rv = sysread($fh, $buf, 64*1024, length($buf)); die $! if !defined($rv); if (!$rv) { delete $children{$fh}; $sel->remove($fh); waitpid($child->{pid}, 0); printf("%s: Exited with %08X after receiving %s\n", $child->{ +id}, $?, $buf); next; } printf("%s: Received some data\n", $child->{id}); } }
1: Received some data 2: Received some data 1: Received some data 2: Received some data 1: Received some data 2: Received some data 1: Received some data 2: Received some data 1: Received some data 1: Exited with 00000000 after receiving aaaaa 2: Received some data 2: Received some data 2: Received some data 2: Exited with 00000000 after receiving aaaaaaa


Comment on Re: Does IO::Select work? Anywhere?
Select or Download Code
Re^2: Does IO::Select work? Anywhere?
by Athanasius (Monsignor) on Oct 21, 2012 at 10:09 UTC

    Doesn’t work for me.  :-(

    I copied-and-pasted the code into a file named “344_SoPW.pl” and ran it with the following results:

    19:46 >perl -c 344_SoPW.pl 344_SoPW.pl syntax OK 19:46 >perl 344_SoPW.pl syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors. syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors. Terminating on signal SIGINT(2) 19:47 >

    (Had to Control-C as it just hung.) My configuration:

    • Windows Vista 32-bit
    • Strawberry perl 5, version 16, subversion 0 (v5.16.0) built for MSWin32-x86-multi-thread-64int
    • IO::Select v1.21
    • IPC::Open3 v1.12
    • Symbol v1.07

    Hope this info is useful,

    Athanasius <°(((><contra mundum

      Doesn’t work for me. ... Windows ...

      It won't. Pipe handles aren't selectable under windows -- which makes it a pretty useless demo for anyone who uses windows.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

      :) Really, you don't have /dev/null on windows? Use File::Spec->devnull

      naturally fixing those portability issues , select loop is forever

      use File::Spec(); sub launch { my ($id) = @_; open(local *TO_CHILD, '<', File::Spec->devnull ) or die $!; *TO_CHILD if 0; my $pid = open3( '<&TO_CHILD', my $from_child = gensym(), '>&STDERR', #~ perl => ( -e => 'use Time::HiRes qw( sleep ); $|=1; for (1..r +and(10)+5) { sleep(0.100 + rand(100)/1000); print "a" }' ), $^X => ( -e => 'use Time::HiRes qw( sleep ); $|=1; for (1..rand( +10)+5) { sleep(0.100 + rand(100)/1000); print q{a} }' ), ); return { id => $id, pid => $pid, pipe => $from_child, buf => '' }; }

      Perl version: v5.14.1 on MSWin32
      Carp               - 1.26
      Devel::VersionDump - 0.02
      Exporter           - 5.66
      File::Spec         - 3.33
      File::Spec::Unix   - 3.33
      File::Spec::Win32  - 3.33
      IO::Select         - 1.20
      IPC::Open3         - 1.09
      Symbol             - 1.07
      constant           - 1.21
      strict             - 1.04
      vars               - 1.02
      warnings           - 1.12
      warnings::register - 1.02

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-11-29 03:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (203 votes), past polls