Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Using Select and pipes to communicate with threads

by BrowserUk (Patriarch)
on Sep 02, 2011 at 10:00 UTC ( [id://923815]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Using Select and pipes to communicate with threads
in thread Using Select and pipes to communicate with threads

My earliest (that I can find), use of pipe with threads (fork is a thread under win32) is 8 years ago.

The most recent I found is February this year.


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.
  • Comment on Re^3: Using Select and pipes to communicate with threads

Replies are listed 'Best First'.
Re^4: Using Select and pipes to communicate with threads
by zentara (Archbishop) on Sep 02, 2011 at 15:10 UTC
    Your first link is a piped-open command, not a pure pipe, and it dosn't use threads at all. A piped open locks the filehandle to a command, whearas a pure pipe is more flexible.

    Your second link has nothing to do with conventional pipes at all, it states

    Instead of passing a handle to the object back to the parent so that it can control it, try giving the parent a shared variable that indicates what it wants the child to do to the object.

    Neither of these show how to setup conventional pipes to threads, let alone show how to read output from many threads/pipes in a simple select loop.

    Sure, there are many ways to do communication between threads and parent, but neither of your examples show how to use IO::Select to monitor multiple threads whose output is directly fed to pipes, an even more precise, an IO::Pipe object.

    Furthermore, I find your code overly complicated, for example you do

    # save STDOUT open(my $STDOUT_ORIG, ">&", \*STDOUT) or die; # connect TO_CHILD_PROC with CHILD_PROC pipe(CHILD_PROC, TO_CHILD_PROC); # change STDOUT to TO_CHILD_PROC # --> STDOUT of child process is set to TO_CHILD_PROC and # this is connected via pipe with CHILD_PROC open(STDOUT, ">&", \*TO_CHILD_PROC);
    Ugh!!!

    When all that is needed is

    # in thread my $wh = $pipe->writer; $wh->autoflush(1); print $wh "whatever \n" ;

    Sorry, but you have not shown any link of yours that uses IO::Select and IO::Pipe in such a clearcut and simple manner, for monitoring multiple threads with 1 loop, as my script does. So I feel it is my right to defend it's virtue and put in Cool Uses for Perl, so others can use the simple technique. Even googling for "perl threads pipe mkfifo" yields few real scripts, and NONE of them combine IO::Select with the simplicity of IO::Pipe.

    So sorry BrowserUk, this time your blusterous hot air dosn't fill the balloon.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      not a pure pipe,

      Of course it is a "pure pipe". The fact that the data is sourced from a command rather than a file is irrelevant.

      As for your mumblings about IO::Pipe. That module didn't work on Win32 back then. Until I helped demerphq fix it a couple of years later.


      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.
        Of course it is a "pure pipe". The fact that the data is sourced from a command rather than a file is irrelevant.

        If that is so, why can't the thread print to that piped filehandle from anywhere in it's code block. A pure pipe can. The only thing that is irrelevant are your criticisms. I think you are jealous of my beautiful baby code, and like an old chron, you just want to bitch about it.


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-23 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found