WeBWorK Main Forum

Infinite loop in problemRandomize.pl?

Infinite loop in problemRandomize.pl?

by Darwyn Cook -
Number of replies: 2
Note: We are running WW updated two weeks ago via cvs update -rrel-2-4-patches webwork (not sure if that is 2.4.7 or 2.4.5) on Centos 4.8


After having used problemRandomize successfully in one problem I tried to install it in PGcourse.pl using the lines:
loadMacros("problemRandomize.pl");
ProblemRandomize(when=>"always",XonlyAfterDue=>1,style=>"Input");
ProblemRandomize(when=>"always",XonlyAfterDue=>0,style=>"Input")
if $studentLogin eq "admin";
# This gives the admin the ability to generate a new problem anytime?

When I went to test it by trying a problem (as admin) the server slowed way down to the point that I had to reboot it (I have noticed before that sometimes the one problem I have working will take a long time to load). Checking the logs here are some of the messages I had:

[Thu Jan 21 12:00:44 2010] [warn] [client 149.84.152.70] [/webwork2/math271cook/Initial_Value_Problems/4/] Deep recursion on subroutine "problemRandomize::grader" at (eval 970) line 356.\n, referer: http://webwork.alfred.edu/webwork2/math
271cook/Initial_Value_Problems/3/
[Thu Jan 21 12:01:47 2010] [warn] [client 149.84.152.70] [/webwork2/math271cook/Initial_Value_Problems/4/] Timeout after processing this problem for 60 seconds. Check for infinite loops in problem source.\n, referer: http://webwork.alfred
.edu/webwork2/math271cook/Initial_Value_Problems/3/
[Thu Jan 21 12:03:03 2010] [warn] [client 149.84.53.65] [/webwork2/math271cook/Introduction_to_Differential_Equations/3/] Timeout after processing this problem for 60 seconds. Check for infinite loops in problem source., referer: http://w
ebwork.alfred.edu/webwork2/math271cook/Introduction_to_Differential_Equations/3/
[Thu Jan 21 12:03:04 2010] [warn] [client 149.84.53.65] [/webwork2/math271cook/Introduction_to_Differential_Equations/3/] Failed to evaluate module Parser: Timeout after processing this problem for 60 seconds. Check for infinite loops in
problem source.\nCompilation failed in require at /opt/webwork/pg/lib/Parser.pm line 795, <DATA> line 365.\nBEGIN failed--compilation aborted at /opt/webwork/pg/lib/Parser.pm line 795, <DATA> line 365.\nCompilation failed in require at (e
val 203) line 1, <DATA> line 365., referer: http://webwork.alfred.edu/webwork2/math271cook/Introduction_to_Differential_Equations/3/
[Thu Jan 21 12:03:05 2010] [warn] [client 149.84.53.65] [/webwork2/math271cook/Introduction_to_Differential_Equations/3/] Failed to evaluate module Value: Timeout after processing this problem for 60 seconds. Check for infinite loops in p
roblem source.\nCompilation failed in require at /opt/webwork/pg/lib/Parser.pm line 795, <DATA> line 365.\nBEGIN failed--compilation aborted at /opt/webwork/pg/lib/Parser.pm line 795, <DATA> line 365.\nCompilation failed in require at (ev
al 203) line 1, <DATA> line 365., referer: http://webwork.alfred.edu/webwork2/math271cook/Introduction_to_Differential_Equations/3/
[Thu Jan 21 12:03:05 2010] [warn] [client 149.84.53.65] [/webwork2/math271cook/Introduction_to_Differential_Equations/3/] Failed to evaluate module Parser::Legacy: Can't call method "copy" on an undefined value at /opt/webwork/pg/lib/Pars
er/Legacy/LimitedNumeric.pm line 81, <DATA> line 365.\nCompilation failed in require at /opt/webwork/pg/lib/Parser/Legacy.pm line 6, <DATA> line 365.\nBEGIN failed--compilation aborted at /opt/webwork/pg/lib/Parser/Legacy.pm line 6, <DATA
> line 365.\nCompilation failed in require at (eval 204) line 1, <DATA> line 365., referer: http://webwork.alfred.edu/webwork2/math271cook/Introduction_to_Differential_Equations/3/
Timeout after processing this problem for 60 seconds. Check for infinite loops in problem source.

The code for problem Initial_Value_problems 4 referred to in the first error:
##DESCRIPTION
## Give students a two parameter solution of a DE, ask them to solve the IVP
##ENDDESCRIPTION

##KEYWORDS('ivp' 'initial' 'value' 'problem')

## DBsubject('Calculus')
## DBchapter('Differential Equations')
## DBsection('Introduction to Differential Equations')
## Date('12/16/2009')
## Author('Darwyn Cook')
## Institution('Alfred University')
## TitleText1('Differential Equations: with Boundary Value Problems')
## EditionText1('6')
## AuthorText1('Zill')
## Section1('1.2')
## Problem1('')

########################################################################

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"PGcourse.pl", # Customization file for the course
);

# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;
Context()->variables->add(y=>"Real");
##############################################################
#
# Setup
#
#
$y0 = Compute(random(1,10));
$dy0 = Compute(random(1,10));

$soln = Formula("$dy0*sin(x)+$y0*cos(x)");

##############################################################
#
# Text
#
#

Context()->texStrings;
BEGIN_TEXT
The differential equation
$BR
\[y^{\prime\prime}+y = 0\]
has one of the following two parameter families as its general solution
$BR
\[
\begin{aligned}
y&=c_1e^x &y&=c_2e^{-x}\\
y&=c_1\cos(x) &y&=c_2\sin(x)\\
y&=c_1\tan(x) &y&=c_2\sec(x)\\
y&=c_1 &y&=c_2x\\
\end{aligned}
\]

$BR
Find the solution such that \(y(0) = $y0\) and \(y^\prime(0)=$dy0\): \{$soln->ans_rule(20)\}
END_TEXT
Context()->normalStrings;

##############################################################
#
# Answers
#
#

ANS($soln->cmp);
ENDDOCUMENT();




In reply to Darwyn Cook

Re: Infinite loop in problemRandomize.pl?

by Davide Cervone -
The problem is that you have called ProblemRandomize() twice. This function does some setup that should only be done once, e.g., it sets up a special grader that caches the current grader and calls that after performing the special grading. If you call it again, it will call itself rather than the original grader, and I'm assuming that is the source of the recursion you are seeing.

In any case, if you use

    ProblemRandomize(when=>"always", onlyAfterDue=>($studentLogin ne "admin"), style=>"Input");
that should have the effect you want.

Davide

PS, the "X" in "XonlyAfterDue" should not be there, but the system keeps putting it in for me and I can't seem to prevent it. Sorry!