Re: threads

From: zentara (zentara_at_highstream.net)
Date: 01/23/05


Date: Sun, 23 Jan 2005 07:30:51 -0500

On Sat, 22 Jan 2005 11:33:12 +0100, Måns Rullgård <mru@inprovide.com>
wrote:

>zentara <zentara@highstream.net> writes:
>
>> On Fri, 21 Jan 2005 17:08:25 -0800, "David Schwartz"
>> <davids@webmaster.com> wrote:
>>
>>> It's too bad it's not really practical to use pools of processes the way
>>>you use pools of threads. That would be an another interesting option that
>>>would give you some of the benefits of both and few of the disadvantages of
>>>either. You'd need a library that simplified things like cross-process
>>>synchronization, objects in shared memory, and file descriptor exchange.
>>>Thesis project anyone?
>>
>> Perl has Parallel::Fork::Manager.
>
>Doesn't seem to be in a standard installation.

>I haven't checked, but I'm pretty certain that thing does a fork each
>time you call it. It's rather simple to keep a counter of how many
>processes have been forked, and wait() for some to finish before
>starting more when the limit has been reached.
>
>I think David was wishing for an easy to use library that pre-forked a
>number of processes, and reused the same processes, much like Apache
>httpd does.

Yeah, you are right. But Perl to the rescue. :-)

I would use IPC::Open3 to open a set of stdin,stdout,stderr
pipes to 'bash' or whatever shell you want, then just send
commands to it to run. The fork'd processes would be reusable
and under the control of the parent process( i.e. kill $pid ).
This is just a simple example, (I've combined the stderr and stdout
to avoid needing to use select). I could have forked more than 1
and I could change the command to send to the bash interpreter
for each refresh.)

I know you fellows prefer to discuss C, but Perl does make alot
of difficult things easy.

#!/usr/bin/perl
use warnings;
use strict;
use IPC::Open3;
use Tk;

$|=1;
my $pid=open3(\*IN,\*OUT,0,'/bin/bash');

my $mw=new MainWindow;
$mw->geometry("600x400");

my $t=$mw->Scrolled('Text',-width => 80,
     -height => 80,
     )->pack;

&refresh;

$mw->fileevent(\*OUT,'readable',\&write_t);
my $id = Tk::After->new($mw,2000,'repeat',\&refresh);

MainLoop;

sub refresh{
print IN "top b n 1";
print IN "\n"; #absolutely needed and on separate line
}

sub write_t {
  my $str= <OUT>;
  $t->insert("1.0",$str);
# $t->see("0.0");
}
__END__

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


Relevant Pages

  • Re: How do you unlock a pivot table on a protected excel sheet?
    ... Sub Refresh() ... >I have a protected worksheet with only input cells unlocked. ... > allow the ordinary user the ability to refresh the pivot table data? ...
    (microsoft.public.excel.worksheet.functions)
  • Re: how to refresh button in the addIn bar
    ... commands in the EnvDTE.IDTCommandTarget.QueryStatus method of your Connect ... There are several buttons in the bar. ... > During IDE build a solution, The AddIn ... > buttons have not been refresh. ...
    (microsoft.public.vsnet.ide)
  • Re: Assign Macro To Button At Runtime
    ... > I am creating a button thru macro and assign a function named Refresh. ... > But macro is executing. ...
    (microsoft.public.excel.programming)
  • Re: Web Query Refersh Interval
    ... I using onTime method, but still have problem with refresh ... Sub Refresh() ... > Kelvin wrote: ...
    (microsoft.public.excel.misc)
  • Re: [opensuse] Firefox controls by Search???
    ... Of course this is very annoying coz i need to refresh most of the ... To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx ... For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx ...
    (SuSE)

Loading