Skip to content

Commit 53cf945

Browse files
author
Philip Guo
committed
more more more
1 parent 8095d33 commit 53cf945

9 files changed

Lines changed: 33 additions & 21 deletions

File tree

cgi-bin/pg_logger.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828

2929
# upper-bound on the number of executed lines, in order to guard against
3030
# infinite loops
31-
MAX_EXECUTED_LINES = 300
31+
MAX_EXECUTED_LINES = 200
3232

33+
def set_max_executed_lines(m):
34+
global MAX_EXECUTED_LINES
35+
MAX_EXECUTED_LINES = m
3336

3437
import sys
3538
import bdb # the KEY import here!

cgi-bin/web_exec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def web_finalizer(output_lst):
9090

9191
form = cgi.FieldStorage()
9292
user_script = form['user_script'].value
93+
if 'max_instructions' in form:
94+
pg_logger.set_max_executed_lines(int(form['max_instructions'].value))
9395

9496
pg_logger.exec_script_str(user_script, web_finalizer)
95-

cgi-bin/web_run_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,16 @@ def really_finalize():
128128
user_script = form['user_script'].value
129129
expect_script = form['expect_script'].value
130130

131-
132131
# WEIRD: always run the expect_script FIRST since it's less likely to have
133132
# errors. for some mysterious reason, if there's an error in user_script,
134133
# then it will never run expect_script
135134
#
136135
# also make sure to ignore IDs so that we can do direct object comparisons!
137136
pg_logger.exec_script_str(expect_script, expect_script_finalizer, ignore_id=True)
138-
pg_logger.exec_script_str(user_script, user_script_finalizer, ignore_id=True)
139137

138+
139+
# set a custom instruction limit only for user scripts ...
140+
if 'max_instructions' in form:
141+
pg_logger.set_max_executed_lines(int(form['max_instructions'].value))
142+
143+
pg_logger.exec_script_str(user_script, user_script_finalizer, ignore_id=True)

edu-python-questions.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,13 @@ function finishQuestionsInit(questionsDat) {
275275

276276
var submittedCode = concatSolnTestCode($("#actualCodeInput").val(), $("#testCodeInput").val());
277277

278+
var postParams = {user_script : submittedCode};
279+
if (questionsDat.max_instructions) {
280+
postParams.max_instructions = questionsDat.max_instructions;
281+
}
282+
278283
$.post("cgi-bin/web_exec.py",
279-
{user_script : submittedCode},
284+
postParams,
280285
function(traceData) {
281286
renderPyCodeOutput(submittedCode);
282287
enterVisualizeMode(traceData);
@@ -300,8 +305,14 @@ function finishQuestionsInit(questionsDat) {
300305
// out-of-order, so code very carefully here!!!
301306
for (var i = 0; i < tests.length; i++) {
302307
var submittedCode = concatSolnTestCode($("#actualCodeInput").val(), tests[i]);
308+
309+
var postParams = {user_script : submittedCode, expect_script : expects[i]};
310+
if (questionsDat.max_instructions) {
311+
postParams.max_instructions = questionsDat.max_instructions;
312+
}
313+
303314
$.post("cgi-bin/web_run_test.py",
304-
{user_script : submittedCode, expect_script : expects[i]},
315+
postParams,
305316
genTestResultHandler(i),
306317
"json");
307318
}
@@ -342,7 +353,7 @@ function gradeSubmission() {
342353
}
343354

344355
if (res.status == 'error') {
345-
$("#gradeMatrix tr.gradeMatrixRow:last").append('<td class="testOutputCell"><span style="padding: 5px; background-color: ' + errorColor + ';">' + res.error_msg + '</span></td>');
356+
$("#gradeMatrix tr.gradeMatrixRow:last").append('<td class="testOutputCell"><span style="padding-left: 3px; padding-right: 3px; background-color: ' + errorColor + '">' + res.error_msg + '</span></td>');
346357
}
347358
else {
348359
assert(res.status == 'ok');

edu-python.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,6 @@ div#editCodeLinkDiv {
190190
margin-bottom: 4px;
191191
}
192192

193-
#warningOutput {
194-
font-size: 9pt;
195-
color: #666666;
196-
}
197-
198193
button.bigBtn {
199194
font-size: 14pt;
200195
padding: 3px;

edu-python.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ function processTrace(traceData, jumpToEnd) {
8383
curInstr = 0;
8484

8585
// delete all stale output
86-
$("#warningOutput").html('');
8786
$("#pyStdout").val('');
8887

8988
if (curTrace.length > 0) {
@@ -95,7 +94,8 @@ function processTrace(traceData, jumpToEnd) {
9594
if (instrLimitReached) {
9695
curTrace.pop() // kill last entry
9796
var warningMsg = lastEntry.exception_msg;
98-
$("#warningOutput").html(htmlspecialchars(warningMsg));
97+
$("#errorOutput").html(htmlspecialchars(warningMsg));
98+
$("#errorOutput").show();
9999
}
100100
// as imran suggests, for a (non-error) one-liner, SNIP off the
101101
// first instruction so that we start after the FIRST instruction
@@ -218,7 +218,9 @@ function updateOutput() {
218218
hasError = true;
219219
}
220220
else {
221-
$("#errorOutput").hide();
221+
if (!instrLimitReached) { // ugly, I know :/
222+
$("#errorOutput").hide();
223+
}
222224
}
223225

224226

index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@
134134
<span id="curInstr">Step ? of ?</span>
135135
<button id="jmpStepFwd", type="button">Forward &gt;</button>
136136
<button id="jmpLastInstr", type="button">Last &gt;&gt;</button>
137-
138-
<p><span id="warningOutput"></span></p>
139137
</div>
140138

141139
<div id="errorOutput"></div>

question.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@
116116
<span id="curInstr">Step ? of ?</span>
117117
<button id="jmpStepFwd", type="button">Forward &gt;</button>
118118
<button id="jmpLastInstr", type="button">Last &gt;&gt;</button>
119-
120-
<p><span id="warningOutput"></span></p>
121119
</div>
122120

123121
<div id="errorOutput"></div>

questions/optimize-search.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Question:
55

66
The following search function finds the index of the first occurrence of
77
elt in a sorted list lst (or -1 if elt not found). Optimize this
8-
function so that it works on a 64-element sorted list using less than 50
9-
instructions.
8+
function so that it works on a 64-element sorted list by executing less
9+
than 50 instructions.
1010

1111
Hint:
1212
Linear search will never work.

0 commit comments

Comments
 (0)