[22377] in Perl-Users-Digest
Perl-Users Digest, Issue: 4598 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 21 03:05:49 2003
Date: Fri, 21 Feb 2003 00:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 21 Feb 2003 Volume: 10 Number: 4598
Today's topics:
Re: /^-?(?:\d+(?:\.\d*)?\d+)$/ <mgjv@tradingpost.com.au>
Re: /^-?(?:\d+(?:\.\d*)?\d+)$/ (Jay Tilton)
Re: Also religious: brackets <shondell@cis.ohio-state.edu>
Re: Chucking up text on word boundaries? (Robert Nicholson)
Re: creating a command line alias <me@privacy.net>
Re: having PERL respond to a key press <hazelbigfoot@gmx.net>
Re: How do I get the current date? <Steffen.Beyer@de.bosch.com>
Re: How do I get the current date? <Steffen.Beyer@de.bosch.com>
Re: How do I get the current date? <Steffen.Beyer@de.bosch.com>
Installation of Bundle::LWP fails on Solaris 9 and Perl (Andre Kruger)
Re: pipe() + fork() + exit() == problem? <goldbb2@earthlink.net>
Re: pipe() + fork() + exit() == problem? <gordan@_NOSPAM_bobich.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 21 Feb 2003 13:06:52 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: /^-?(?:\d+(?:\.\d*)?\d+)$/
Message-Id: <slrnb5b2ds.h2.mgjv@martien.heliotrope.home>
On Thu, 20 Feb 2003 19:52:09 -0600,
Ryan McCarthy <remccart@uiuc.edu.spam> wrote:
> Uri Guttman wrote:
>>>>>>>"RM" == Ryan McCarthy <remccart@uiuc.edu.spam> writes:
>>
>>
>> RM> Can somebody provide me some insight as to why the following matches
>> RM> numbers like 25, 25.0, 5.0 but NOT '5'? Thanks!
>>
>> RM> /^-?(?:\d+(?:\.\d*)?\d+)$/
>> ^^^ ^^^
>>
>> each of those matches at least 1 digit so single digit numbers will
>> never be matched
>
> So how would I make it match both .7 and 5?
I think you are looking for the answer to the question "How do I
determine whether a scalar is a number/whole/integer/float?" in the Perl
FAQ, section 4.
perldoc perlfaq4
Martien
--
|
Martien Verbruggen | If it isn't broken, it doesn't have enough
| features yet.
|
------------------------------
Date: Fri, 21 Feb 2003 02:23:13 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: /^-?(?:\d+(?:\.\d*)?\d+)$/
Message-Id: <3e558d53.70512032@news.erols.com>
On Thu, 20 Feb 2003 19:52:09 -0600, Ryan McCarthy
<remccart@uiuc.edu.spam> wrote:
: Uri Guttman wrote:
: >>>>>>"RM" == Ryan McCarthy <remccart@uiuc.edu.spam> writes:
: >
: >
: > RM> Can somebody provide me some insight as to why the following matches
: > RM> numbers like 25, 25.0, 5.0 but NOT '5'? Thanks!
: >
: > RM> /^-?(?:\d+(?:\.\d*)?\d+)$/
: > ^^^ ^^^
: >
: > each of those matches at least 1 digit so single digit numbers will
: > never be matched
:
: So how would I make it match both .7 and 5?
There are some good suggestions in perlfaq4,
"How do I determine whether a scalar is a number/whole/integer/float?"
------------------------------
Date: 21 Feb 2003 00:27:43 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: Also religious: brackets
Message-Id: <xcw4r6ymcds.fsf@psi.cis.ohio-state.edu>
Abigail <abigail@abigail.nl> writes:
> Ryan Shondell (shondell@cis.ohio-state.edu) wrote on MMMCDLX September
> MCMXCIII in <URL:news:xcw8ywaooll.fsf@psi.cis.ohio-state.edu>:
> ** Malte Ubl <ubl@schaffhausen.de> writes:
> **
> ** > Ryan Shondell wrote:
> ** > > "Peter Cooper" <newsfeed2@boog.co.uk> writes:
(snip)
> ** > >>$debug && print $variable;
> ** > > Wow, that's almost a carbon-copy example of what perlstyle says _not_
> ** >
> ** > > to do, because it hides the main point of the statement.
> ** >
> ** > No it doesn't, because here you got the very import C<$debug> as the
> ** > first word on the line. I prefer the written C<and> though.
> **
> ** The part from perlstyle that I am refering to is:
> **
>
> But giving any authority to 'perlstyle' contradicts 'perlstyle' itself:
>
> Larry has his reasons for each of these things, but he
> doesn't claim that everyone else's mind works the same as
> his does.
Still, there is much advice in there that is sound (and sane) that
many novice (and even not-so novice) programmers may not realize. But
I'm sure no one follows _all_ the stuff in there. I know I don't. :)
It was just eerie seeing that particular example posted here, right
after I was looking through perlstyle. I thought it might have been a
bit of a troll at first glance (of course, it's not...lack of
caffeine, I guess), giving an example that happens to be almost
exactly the same as the example in the docs.
--
Ryan Shondell <shondell@cis.ohio-state.edu>
------------------------------
Date: 20 Feb 2003 20:03:23 -0800
From: robert@elastica.com (Robert Nicholson)
Subject: Re: Chucking up text on word boundaries?
Message-Id: <24a182bd.0302202003.e0f9882@posting.google.com>
Actually I did but I cannot get it to wrap anything. It seems to not
split any of the lines I'm giving it. I'll look at it some more
shortly.
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message news:<Xns932888705A19Esdn.comcast@216.166.71.239>...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> robert@elastica.com (Robert Nicholson) wrote in
> news:24a182bd.0302200631.7a81702c@posting.google.com:
>
> > Are there any examples of taking a large string and cutting it up into
> > smaller pieces where each "chunk" is split on a word boundary?
>
> Suggest you look into the Text::Wrap module.
>
> - --
> Eric
> print scalar reverse sort qw p ekca lre reh
> ts uJ p, $/.r, map $_.$", qw e p h tona e;
>
>
> -----BEGIN xxx SIGNATURE-----
> Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
>
> iQA/AwUBPlUdZ2PeouIeTNHoEQL6ZACfbyvxKRsPh18NGmQKKfp8xExf9K4AoKsH
> zA5wRnqSAjlvHybBTfzmHGfp
> =TMDB
> -----END PGP SIGNATURE-----
------------------------------
Date: Fri, 21 Feb 2003 17:14:05 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: creating a command line alias
Message-Id: <b34g3i$1ij6ge$1@ID-172104.news.dfncis.de>
"Joe Hasting" <hasting@agere.com> wrote in message
news:b33lms$3o0$1@test-nntp.agere.com...
> > perldoc -q environment
>
> I am not sure how to access the FAQ from the command you've written, could
> you give more instruction?
If you have Perl installed locally on your computer, simply type in the
command given.
If you don't have Perl installed locally or where you have command line
access, go to
http://perldoc.com/
See Perl FAQ 8 - "I {changed directory, modified my environment} in a perl
script. How come the change disappeared when I exited the script? How do
I get my changes to be visible?"
------------------------------
Date: Fri, 21 Feb 2003 08:52:15 +0100
From: Jens Hoehne <hazelbigfoot@gmx.net>
Subject: Re: having PERL respond to a key press
Message-Id: <3E55DAAF.6060509@gmx.net>
tyrannous@o-space.com wrote:
> I want to have perl exit from a WHILE loop when the user presses a certain
> key on the keyboard
>
> for example of what i want:
>
> while(not $something)
> {
>
> if($keypress eq "a")
> {
>
> do something
>
> }
>
> }
perldoc perlsyn
Do you mean something like: last if ($keypress eq 'a')
>
> before you answer this question, remember that i have already tried
> Term::ReadKey and it wont work on my MS-DOS system. plz help me if you can
>
I remember you have already posted this some days ago and were referred
to the faq. There is also a section in
perldoc -q keyboard
for msdos systems. Have you tried that? I am not working on dos, but I
am sure, other with more experience can help you, if you tell them, what
exactly you tried and what errors happended.
Regards,
Jens
------------------------------
Date: Fri, 21 Feb 2003 08:02:19 +0100
From: "Steffen Beyer" <Steffen.Beyer@de.bosch.com>
Subject: Re: How do I get the current date?
Message-Id: <b34itt$hn8$1@ns2.fe.internet.bosch.com>
"Helgi Briem" <helgi@decode.is> wrote in message news:3e54d614.1128664573@news.cis.dfn.de...
> On Thu, 20 Feb 2003 13:25:25 +0100, "Steffen Beyer"
> <Steffen.Beyer@de.bosch.com> wrote:
> >Without the penalty for loading an additional module,
> >how about this:
>
> Please, please don't spread misinformation about
> the "penalty for loading an additional module".
>
> If the nanoseconds/kilobytes penalty of loading
> a module is actually important to you, you shouldn't
> be programming in Perl.
I agree in principle, but I have reason to disagree in particular.
I have seen CGI applications which used so many modules that
they really slowed down considerably. So there are cases in
which it makes sense to avoid loading modules.
But in general, it is of course a good idea not to re-invent
the wheel and to use modules wherever possible.
I'm the last to object because I'm a module author myself. :-)
Cheers,
Steffen
------------------------------
Date: Fri, 21 Feb 2003 08:11:10 +0100
From: "Steffen Beyer" <Steffen.Beyer@de.bosch.com>
Subject: Re: How do I get the current date?
Message-Id: <b34jeh$i32$1@ns2.fe.internet.bosch.com>
> ?? And even though ISO 8601 also defines several possible variations,
> ?? they all have in common the order year-month-day (or somesuch
> ?? sensible order) which makes them easily sortable, which was the
> ?? point in question in the first place. :-)
>
> Actually, they don't. DDDD-DDD is an allowed format, meaning year and
> day of the year. Days may also be left off, DDDD-DD means a month in a
> certain year. But both the century and the dash may be left off, giving
> you DDDD. And there's DDDDWDD and DDDDWDDD, the first one pointing to
> a week in a certain year, the latter to a day in a week in a certain year.
That's exactly what I meant by "or somesuch sensible order". The point is
that once you select one of these formats and use it for both dates which
you want to compare, a string compare will suffice (to the degree of
precision offered by the chosen format).
But you know all that already, so this discussion really is academic, isn't it? :-)
Best regards,
Steffen
------------------------------
Date: Fri, 21 Feb 2003 08:19:56 +0100
From: "Steffen Beyer" <Steffen.Beyer@de.bosch.com>
Subject: Re: How do I get the current date?
Message-Id: <b34juu$ics$1@ns2.fe.internet.bosch.com>
> {} > > I want to write a script that zip up files, and names the archive
> {} > > file-month-day-year.zip
> {} > > How do I get the current date in a perl script?
> {} my @now = localtime();
> {} $now[4]++;
> {} $now[5] += 1900;
> {} my $file = sprintf("file-%04d%02d%02d.zip", @now[5,4,3]);
> Well, that would do year, month, day, wouldn't it?
Correct. :-)
This is because I also second the second poster's suggestion
to use a sortable format (i.e. year-month-day) instead of
month-day-year.
> The request was about month, day, year.
It should be obvious from the suggested solution that you can
easily achieve any order you like by shifting the numbers 5,4,3
around... :-)
> {} And yes, this has a Y10K bug (sort of). ;-)
> What makes you think there's a Y10K bug?
The fact that I wrote %04d in the sprintf.
Which BTW is unnecessary for the next (roughly) 8000 years
(in theory - in practice localtime will break in 2038 on
32 bit machines).
This is almost a bug because in year 10000, the sprintf will
automatically use 5 digits for the year (despite the %04d) -
which may break other code which expects 4 digits only.
Cheers,
Steffen
------------------------------
Date: 20 Feb 2003 23:59:15 -0800
From: akruger@etilize.com (Andre Kruger)
Subject: Installation of Bundle::LWP fails on Solaris 9 and Perl 5.8.0
Message-Id: <1b37d11c.0302202359.4995b72@posting.google.com>
When I try to install Bundle::LWP I get a failure message that says
that:
Bundle summary: The following items in bundle Bundle::LWP had
installation
problems:
MIME::Base64
ok ... never to be daunted I decide to install MIME::Base64 by hand
I download the module again (just to be safe)
I extract and go into the directory
I do a perl Makefile.PL
make
make test (no tests fail as you can see from the output below)
make install
Everything seems to be ok ... I get the /usr/local/bin/decode-base64
and friends installed ... but still the Bundle::LWP fails ..... it
keeps trying to reload MIME::Base64
Any help would be appreciated.
output from manual build of MIME::Base64
23:43:48:greenwater:root>cd MIME-Base64-2.16/
23:43:53:greenwater:root>perl Makefile.PL
Writing Makefile for MIME::Base64
23:44:06:greenwater:root>make
gcc -B/usr/ccs/bin/ -c -fno-strict-aliasing -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -O -DVERSION=\"2.16\" -DXS_VERSION=\"2.16\"
-fPIC "-I/usr/local/lib/perl5/5.8.0/sun4-solaris-64int/CORE"
Base64.c
Running Mkbootstrap for MIME::Base64 ()
chmod 644 Base64.bs
rm -f blib/arch/auto/MIME/Base64/Base64.so
LD_RUN_PATH="" gcc -B/usr/ccs/bin/ -G -L/usr/local/lib Base64.o -o
blib/arch/auto/MIME/Base64/Base64.so
chmod 755 blib/arch/auto/MIME/Base64/Base64.so
cp Base64.bs blib/arch/auto/MIME/Base64/Base64.bs
chmod 644 blib/arch/auto/MIME/Base64/Base64.bs
cp decode-qp blib/script/decode-qp
/usr/local/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)"
blib/script/decode-qpcp encode-qp blib/script/encode-qp
/usr/local/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)"
blib/script/encode-qpcp decode-base64 blib/script/decode-base64
/usr/local/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)"
blib/script/decode-base64
cp encode-base64 blib/script/encode-base64
/usr/local/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)"
blib/script/encode-base64
Manifying blib/man3/MIME::QuotedPrint.3
Manifying blib/man3/MIME::Base64.3
23:44:21:greenwater:root>make test
PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e"
"test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/base64..........ok
t/quoted-print....ok
t/unicode.........ok
All tests successful.
Files=3, Tests=321, 1 wallclock secs ( 0.70 cusr + 0.11 csys = 0.81
CPU)
23:44:35:greenwater:root>make install
Files found in blib/arch: installing files in blib/lib into
architecture dependent library tree
Writing /usr/local/lib/perl5/site_perl/5.8.0/sun4-solaris-64int/auto/MIME/Base64/.packlist
Appending installation info to
/usr/local/lib/perl5/5.8.0/sun4-solaris-64int/perllocal.pod
23:44:45:greenwater:root>
Output from building Bundle::LWP
23:49:12:greenwater:root>perl -MCPAN -e 'install Bundle::LWP'
CPAN: Storable loaded ok
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
ftp://archive.progeny.com/CPAN/authors/01mailrc.txt.gz
Going to read /home/akruger/.cpan/sources/authors/01mailrc.txt.gz
CPAN: Compress::Zlib loaded ok
Fetching with LWP:
ftp://archive.progeny.com/CPAN/modules/02packages.details.txt.gz
Going to read /home/akruger/.cpan/sources/modules/02packages.details.txt.gz
Database was generated on Thu, 20 Feb 2003 21:26:18 GMT
Fetching with LWP:
ftp://archive.progeny.com/CPAN/modules/03modlist.data.gz
Going to read /home/akruger/.cpan/sources/modules/03modlist.data.gz
Going to write /home/akruger/.cpan/Metadata
Running install for module MIME::Base64
Running make for G/GA/GAAS/MIME-Base64-2.16.tar.gz
Fetching with LWP:
ftp://archive.progeny.com/CPAN/authors/id/G/GA/GAAS/MIME-Base64-2.16.tar.gz
CPAN: Digest::MD5 loaded ok
Fetching with LWP:
ftp://archive.progeny.com/CPAN/authors/id/G/GA/GAAS/CHECKSUMS
Checksum for /home/akruger/.cpan/sources/authors/id/G/GA/GAAS/MIME-Base64-2.16.tar.gz
ok
Scanning cache /home/akruger/.cpan/build for sizes
MIME-Base64-2.16/
MIME-Base64-2.16/README
MIME-Base64-2.16/QuotedPrint.pm
MIME-Base64-2.16/MANIFEST
MIME-Base64-2.16/decode-qp
MIME-Base64-2.16/encode-base64
MIME-Base64-2.16/encode-qp
MIME-Base64-2.16/Base64.pm
MIME-Base64-2.16/Changes
MIME-Base64-2.16/Makefile.PL
MIME-Base64-2.16/t/
MIME-Base64-2.16/t/unicode.t
MIME-Base64-2.16/t/quoted-print.t
MIME-Base64-2.16/t/base64.t
MIME-Base64-2.16/decode-base64
MIME-Base64-2.16/Base64.xs
CPAN.pm: Going to build G/GA/GAAS/MIME-Base64-2.16.tar.gz
Checking if your kit is complete...
Looks good
Writing Makefile for MIME::Base64
cp QuotedPrint.pm blib/lib/MIME/QuotedPrint.pm
cp Base64.pm blib/lib/MIME/Base64.pm
/usr/local/bin/perl /usr/local/lib/perl5/5.8.0/ExtUtils/xsubpp
-typemap /usr/local/lib/perl5/5.8.0/ExtUtils/typemap Base64.xs >
Base64.xsc && mv Base64.xsc Base64.c
gcc -B/usr/ccs/bin/ -c -fno-strict-aliasing -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -O -DVERSION=\"2.16\" -DXS_VERSION=\"2.16\"
-fPIC "-I/usr/local/lib/perl5/5.8.0/sun4-solaris-64int/CORE"
Base64.c
Running Mkbootstrap for MIME::Base64 ()
chmod 644 Base64.bs
rm -f blib/arch/auto/MIME/Base64/Base64.so
LD_RUN_PATH="" gcc -B/usr/ccs/bin/ -G -L/usr/local/lib Base64.o -o
blib/arch/auto/MIME/Base64/Base64.so
chmod 755 blib/arch/auto/MIME/Base64/Base64.so
cp Base64.bs blib/arch/auto/MIME/Base64/Base64.bs
chmod 644 blib/arch/auto/MIME/Base64/Base64.bs
cp decode-qp blib/script/decode-qp
/usr/local/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)"
blib/script/decode-qp
cp encode-qp blib/script/encode-qp
/usr/local/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)"
blib/script/encode-qp
cp decode-base64 blib/script/decode-base64
/usr/local/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)"
blib/script/decode-base64
cp encode-base64 blib/script/encode-base64
/usr/local/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)"
blib/script/encode-base64
Manifying blib/man3/MIME::QuotedPrint.3
Manifying blib/man3/MIME::Base64.3
/usr/ccs/bin/make -- OK
Running make test
PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e"
"test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/base64..........ok
t/quoted-print....ok
t/unicode.........ok
All tests successful.
Files=3, Tests=321, 2 wallclock secs ( 0.67 cusr + 0.15 csys = 0.82
CPU)
/usr/ccs/bin/make test -- OK
Running make install
Files found in blib/arch: installing files in blib/lib into
architecture dependent library tree
Writing /usr/local/lib/perl5/site_perl/5.8.0/sun4-solaris-64int/auto/MIME/Base64/.packlist
Appending installation info to
/usr/local/lib/perl5/5.8.0/sun4-solaris-64int/perllocal.pod
/usr/ccs/bin/make install -- OK
Digest::MD5 is up to date.
URI is up to date.
Net::FTP is up to date.
HTML::Tagset is up to date.
HTML::Parser is up to date.
HTML::HeadParser is up to date.
LWP is up to date.
Bundle summary: The following items in bundle Bundle::LWP had
installation
problems:
MIME::Base64
23:50:41:greenwater:root>
Andre Kruger
mailto akruger@etilize.com
------------------------------
Date: Thu, 20 Feb 2003 22:10:34 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: pipe() + fork() + exit() == problem?
Message-Id: <3E5598AA.DC8CB8AC@earthlink.net>
Gordan wrote:
[snip]
> Each worker thread reads a setting from an .ini file that tells it
> what it's "time to live" is. When that many jobs are processed, the
> process exits.
Why? I would think that it would be more sensible for workers to simply
keep working until there are no more jobs.
> The parent does a wait() loop, and whenever it finds that a process
> has exited, it checks if all the tasks are complete.
Hmm, it would be easier if, just before exiting, a worker process would
write to the response pipe a message indicating it's exiting; possibly,
this would be part of the response for the last job that it completed.
Upon receiving a 'exiting now' message from a child, the parent process
would call waitpid($childpid, 0)... it wouldn't need to do a wait loop
of any sort.
> If they are, it just waits until all processes exit. If there are
> still jobs left to be done, it forks another process to replace the
> one that just exited.
I still don't see the purpose of this.... well, I suppose that if the
worker processes are leaking memory or other resources, and the only way
you can think for reclaiming that is to have them die and get restarted,
then I *guess* it makes a bit of sense, but otherwise, it's a fairly
silly way to go about doing things.
> I didn't use the method of just closing the input pipe on the process
> because I wasn't sure if an empty pipe would make the process detect
> an EOF, too.
If no process has an open handle to the write-end of a pipe, then any
process reading from the read-end of the pipe will get EOF, once all the
data that was in the pipe is removed.
> Sometimes the output queue is filled slower than the processing speed,
> so threads can decide to sleep() for a while and re-try a few times
> before deciding that the load is low enough that they are no longer
> useful.
HUH? Are you doing something funky like making your pipes nonblocking?
You should *never* need to sleep() until a job is ready -- simply try
reading from the pipe, and if you haven't made the pipe nonblocking, it
will *automaticaly* go to sleep until something is available.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Fri, 21 Feb 2003 07:39:48 +0000
From: Gordan <gordan@_NOSPAM_bobich.net>
Subject: Re: pipe() + fork() + exit() == problem?
Message-Id: <1045813187.504030@auth2.dns.griffin.net.uk>
Benjamin Goldberg wrote:
> Gordan wrote:
> [snip]
>> Each worker thread reads a setting from an .ini file that tells it
>> what it's "time to live" is. When that many jobs are processed, the
>> process exits.
>
> Why? I would think that it would be more sensible for workers to
> simply keep working until there are no more jobs.
Memory leaks. This is a long running batch application, and for some
reason, the garbage collector doesn't always release all the unused
memory (no, I don't use references or other things that could
potentially confuse the GC). This means that the memory consumption
increases steadily until the machine falls over.
Limiting each worker to a specific TTL cured the problem nicely. It also
means that the memory common between the processes doesn't get unshared
over time (5+ MB initially, down to 2 MB after about 24 hours), so
there is a memory saving there as well.
>> The parent does a wait() loop, and whenever it finds that a process
>> has exited, it checks if all the tasks are complete.
>
> Hmm, it would be easier if, just before exiting, a worker process
> would write to the response pipe a message indicating it's exiting;
> possibly, this would be part of the response for the last job that it
> completed.
There is no communications/response pipe. Things just get processed
until there is nothing left to do.
> Upon receiving a 'exiting now' message from a child, the parent
> process would call waitpid($childpid, 0)... it wouldn't need to do a
> wait loop of any sort.
wait() blocks anyway, so there is no overhead there.
>> If they are, it just waits until all processes exit. If there are
>> still jobs left to be done, it forks another process to replace the
>> one that just exited.
>
> I still don't see the purpose of this.... well, I suppose that if the
> worker processes are leaking memory or other resources, and the only
> way you can think for reclaiming that is to have them die and get
> restarted, then I *guess* it makes a bit of sense, but otherwise, it's
> a fairly silly way to go about doing things.
Yup, it's the memory leaks that I'm trying to defeat. I've tried
everything else, including moving all variable declarations to the
smalles possible scope (I usually declare them at the top of each
function), and that somewhat slowed down the problem, but after 24
hours or so, the process would still consume all available memory and
die horribly.
>> Sometimes the output queue is filled slower than the processing
>> speed, so threads can decide to sleep() for a while and re-try a few
>> times before deciding that the load is low enough that they are no
>> longer useful.
>
> HUH? Are you doing something funky like making your pipes
> nonblocking?
Effectively, I'm doing something like this:
while (1)
{
flock($Pipe, LOCK_EX);
if (-s $Pipe)
{
$Job = DeQueue($Pipe);
Process($Job);
}
else
{
sleep(5);
}
flock($Pipe, LOCK_UN);
}
> You should *never* need to sleep() until a job is ready -- simply try
> reading from the pipe, and if you haven't made the pipe nonblocking,
> it will *automaticaly* go to sleep until something is available.
Hmm... I might play with that in a bit. It seems like a sensible way to
do it. At the moment, I just have an array mapped into a shared memory
segment that keeps track of status of each thread. If all the jobs are
done, thenthe pipe may never get filled. So, I guess I could check for
an EOF, and make the queue process the first one to exit. It would save
a bit on overhead. Thanks, I think I'll do that. :-)
Regards.
Gordan
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4598
***************************************