Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

WWW::Mechanize->click_button gets perl to 100% cpu use and ends up never finishing

I am posting invoices to sql-ledger (sql-ledger.org) via WWW::Mechanize:

  $request = $self->{_mech}->get('http://localhost/sql-ledger/is.pl?path=bin/mozilla&action=add&level=AR--Sales%20Invoice&login=sync4obmondo@sl-example-aps&js=1&type=invoice');
  $self->{_mech}->form_name('main');
  $self->{_mech}->field('customernumber','10');
  $self->{_mech}->click_button( value => 'Update' ); #submit button 1

  $self->{_mech}->form_name('main');
  $self->{_mech}->field('transdate', $invoicedate);
  $self->{_mech}->field('duedate', $invoicedate);
  $self->{_mech}->field('invnumber', $invoice->invoiceNr);
  print "entering exch." . $invoice->exchangeRate ."-" if $debug;

  #build invoice lines 
  my $count = 0;
  my $invoicelines = ''; my $linedata = '';
  my $outputbefore = '';
  for my $i (1 .. $invoice->getInvoiceLinesAmount() -1)
  {
    $count++;
    my $line = $invoice->getInvoiceLine($i);
    print "line: $count - Entering partnumber".$line->itemPartNr ."
" if $debug;
    #BUG TODO: uncomment this to skip 11th line and above - where timeout becomes too great
    next if $count >= 11;
    $self->{_mech}->field('partnumber_'.$count, $line->itemPartNr);
    print "Updating..
" if $debug;
    $self->{_mech}->click_button( value => 'Update' ); #submit button 1
    if ( $debug ) {
      if ( $outputbefore ne '' ) {
        my $string = $self->{_mech}->content;
        my $diff = diff $outputbefore,  $string;
        #print $diff;
        #print Dumper($diff)
      }
      $outputbefore = $self->{_mech}->content;
    }
    #verify return shows description_$count - NOT empty
    if ( $self->{_mech}->value('description_'.$count) eq "" ) {
      print $self->{_mech}->content;
      die("field $count description NOT filled out. was:".$self->{_mech}->value('description_'.$count));
    }
    $self->{_mech}->form_name('main');
    $self->{_mech}->field('qty_'.$count, $line->amount);
    $self->{_mech}->field('sellprice_'.$count, $line->price);
    $self->{_mech}->field('discount_'.$count, $line->discountPercentage);
    print "submitting qty:".$line->amount." sellprice:". $line->price ." discount:".$line->discountPercentage."
" if $debug;
    $self->{_mech}->click_button( value => 'Update' ); #submit button 1
  }

It hangs on the: $self->{_mech}->click_button( value => 'Update' )

and when an invoice has =>11 lines - my perl process simply goes to a 100% cpu and never finishes (times out after 5 minutes). Until 9 lines it goes very fast, on the 10. line its slow - and the 11. never finishes before the 600 seconds is up.

I was hoping someone has an idea on what's up here? Or what I can try differently? top shows its my perl process - and not sql-ledger thats slow, and indeed if I manually enter the invoice, I have no issues.

Only hits I can find, is to try www::Mechanize::Firefox - but that's discontinued :(

Would submit_form perform better than click_button?

I had to paste the html here: https://pastebin.com/Usn36Jb2

it is a humongous form (and not using <form element but some span..)

I'm using WWW::Mechanize version 1.92


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...