SAForkAndTest

Adrian Bridgett adrian at smop.co.uk
Thu Sep 26 23:12:56 IST 2002


On Thu, Sep 26, 2002 at 22:57:06 +0100 (+0000), Julian Field wrote:
> There are 2 mail reasons why I wrap up the SpamAssassin calls inside evals
> and forks. 1, SA leaks memory like a sieve, as you have found. 2, it
> doesn't always terminate in reasonable time. When I first wrote support for
> SA, it was relatively easy for it to hit a regexp that took about 24 hours
> to evaluate, due to all the back-tracking that was in the regexp. So I
> *had* to implement timeouts round it, as otherwise it was unusable. I won't
> release code to people that could fail quite so spectacularly :-)

Why can't you can leave the timeouts in?:
  $timeout = 2;
  eval {
    local $SIG{ALRM} = sub { die "Command Timed Out" };
    alarm $timeout;
      my $spamness = = $Test->check($Mail);
      $SAHits = $spamness->get_hits();
#      sleep 5;
      $SAReqHits = $spamness->get_required_hits();
      $SAHitList = $spamness->get_names_of_tests_hit();
    alarm 0;
    $SAHits = $SAHits + 0.0;
    $SAReqHits = $SAReqHits + 0.0;
  };
  alarm 0;

  print $@ if $@;

> So yes, I admit that the resulting code is not as fast as it absolutely
> could be, but I prefer reliability to a few % of raw speed. You'll never
> get people using a system which is 5% faster but very unreliable :-)

I'm not normally one to pass up an opportunity to dis windows (think 50%
slower in sentence above), but maybe just the once..

> I haven't ever looked at Data::Dumper though. What can it do for me?

It will dump perl structures in a way that can be eval()ed:

perl -e '%a=("foo"=>"bar","one"=>"two");
         use Data::Dumper;
         print Data::Dumper->Dump([\%a])'

prints:
$VAR1 = {
          'one' => 'two',
          'foo' => 'bar'
         };

I was wondering if this may help pass stuff through pipes - I know ATM you
are only passing simple strings, but maybe this would be useful in the future?

Adrian

Email: adrian at smop.co.uk
Windows NT - Unix in beta-testing. GPG/PGP keys available on public key servers
Debian GNU/Linux  -*-  By professionals for professionals  -*-  www.debian.org



More information about the MailScanner mailing list