Skip to content

Commit 86eac9f

Browse files
committed
Merge branch 'master' of github.com:pgbovine/OnlinePythonTutor
2 parents 999b529 + 6fbf0a3 commit 86eac9f

10 files changed

Lines changed: 129 additions & 7 deletions

File tree

‎v3/opt_togetherjs/Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
all:
44
jshint server.js && node server.js --host 0.0.0.0 --port 30035
55

6+
deps:
7+
npm install websocket optimist
8+
69
prod:
710
#jshint server.js && forever -l togetherjs_server.log server.js --host 0.0.0.0 --port 30035
811
# on Linode:

‎v4-cokapi/backends/javascript/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ diffall:
2020
jshint jslogger.js && python golden_test.py --diffall
2121

2222
# run this before creating any Docker containers
23+
# super weird -- need eval@0.1.0 or else line numbers don't show up on syntax errors!
2324
deps:
24-
npm install eval underscore minimist source-map typescript
25+
npm install eval@0.1.0 underscore minimist source-map typescript@1.4
2526
tar -xvf node-v6.0.0-linux-x64.tar.xz

‎v4-cokapi/backends/javascript/jslogger.js‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ TypeScript TODOs:
8787
/* global Debug */
8888
"use strict";
8989

90+
// super weird -- need eval@0.1.0 or else line numbers don't show up on syntax errors!
91+
// A HA! see this option in the vm module (https://nodejs.org/api/vm.html),
92+
// which the new version of eval turns to false:
93+
// displayErrors: if true, on error, attach the line of code that
94+
// caused the error to the stack trace. Applies only to syntax errors
95+
// compiling the code; errors while running the code are controlled by
96+
// the options to the script's methods.
9097
var _eval = require('eval');
9198
var util = require('util');
9299
var fs = require('fs');
@@ -1083,7 +1090,13 @@ try {
10831090
debug.setBreakOnException(); // for exception handling
10841091
//debug.setBreakOnUncaughtException(); // doesn't seem to do anything :/
10851092

1086-
_eval(wrappedCod, 'userscript.js', {} /* scope */, true /* includeGlobals */);
1093+
var overrideScope = {
1094+
setInterval: () => {throw 'Error: setInterval() is not supported by Python Tutor'},
1095+
setTimeout: () => {throw 'Error: setTimeout() is not supported by Python Tutor'},
1096+
setImmediate: () => {throw 'Error: setImmediate() is not supported by Python Tutor'},
1097+
}
1098+
1099+
_eval(wrappedCod, 'userscript.js', overrideScope /* scope */, true /* includeGlobals */);
10871100
}
10881101
catch (e) {
10891102
// for some reason, the node debugger doesn't allow us to keep going
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{ code: 'setImmediate(() => {console.log("foo")}, 1000);',
2+
trace:
3+
[ { stdout: '',
4+
func_name: '',
5+
stack_to_render: [],
6+
globals: {},
7+
ordered_globals: [],
8+
line: 1,
9+
col: 0,
10+
event: 'step_line',
11+
heap: {} },
12+
{ exception_msg: 'Error: setImmediate() is not supported by Python Tutor',
13+
stdout: '',
14+
func_name: '',
15+
stack_to_render: [],
16+
globals: {},
17+
ordered_globals: [],
18+
line: 1,
19+
col: 0,
20+
event: 'exception',
21+
heap: {} } ] }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setImmediate(() => {console.log("foo")}, 1000);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{ code: 'setInterval(() => {console.log("foo")}, 1000);',
2+
trace:
3+
[ { stdout: '',
4+
func_name: '',
5+
stack_to_render: [],
6+
globals: {},
7+
ordered_globals: [],
8+
line: 1,
9+
col: 0,
10+
event: 'step_line',
11+
heap: {} },
12+
{ exception_msg: 'Error: setInterval() is not supported by Python Tutor',
13+
stdout: '',
14+
func_name: '',
15+
stack_to_render: [],
16+
globals: {},
17+
ordered_globals: [],
18+
line: 1,
19+
col: 0,
20+
event: 'exception',
21+
heap: {} } ] }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setInterval(() => {console.log("foo")}, 1000);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{ code: 'setTimeout(() => {console.log("foo")}, 1000);',
2+
trace:
3+
[ { stdout: '',
4+
func_name: '',
5+
stack_to_render: [],
6+
globals: {},
7+
ordered_globals: [],
8+
line: 1,
9+
col: 0,
10+
event: 'step_line',
11+
heap: {} },
12+
{ exception_msg: 'Error: setTimeout() is not supported by Python Tutor',
13+
stdout: '',
14+
func_name: '',
15+
stack_to_render: [],
16+
globals: {},
17+
ordered_globals: [],
18+
line: 1,
19+
col: 0,
20+
event: 'exception',
21+
heap: {} } ] }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setTimeout(() => {console.log("foo")}, 1000);

‎v4-cokapi/cokapi.js‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ var NODE_BIN = '/usr/local/bin/node';
5757
var PYTHON2_BIN = '/usr/bin/python';
5858
var PYTHON3_BIN = '/usr/local/bin/python3.3';
5959

60-
var TIMEOUT_SECS = 3;
60+
var TIMEOUT_SECS = 5;
6161
var JAVA_TIMEOUT_SECS = 15; // the Java backend is SUPER SLOW :/
62+
var CPP_TIMEOUT_SECS = 15; // the C/C++ backend is also SUPER SLOW :/
63+
64+
var MAX_BUFFER_SIZE = 10 * 1024 * 1024;
6265

6366

6467
// bind() res and useJSONP before using
@@ -149,7 +152,7 @@ function exec_js_handler(useJSONP /* use bind first */, isTypescript /* use bind
149152

150153
child_process.execFile(exeFile, args,
151154
{timeout: TIMEOUT_SECS * 1000 /* milliseconds */,
152-
maxBuffer: 5000 * 1024 /* 5MB data max */,
155+
maxBuffer: MAX_BUFFER_SIZE,
153156
// make SURE docker gets the kill signal;
154157
// this signal seems to allow docker to clean
155158
// up after itself to --rm the container, but
@@ -199,7 +202,7 @@ function exec_java_handler(useJSONP /* use bind first */, req, res) {
199202

200203
child_process.execFile(exeFile, args,
201204
{timeout: JAVA_TIMEOUT_SECS * 1000 /* milliseconds */,
202-
maxBuffer: 5000 * 1024 /* 10MB data max */,
205+
maxBuffer: MAX_BUFFER_SIZE,
203206
// make SURE docker gets the kill signal;
204207
// this signal seems to allow docker to clean
205208
// up after itself to --rm the container, but
@@ -232,7 +235,41 @@ function exec_ruby_handler(useJSONP /* use bind first */, req, res) {
232235

233236
child_process.execFile(exeFile, args,
234237
{timeout: TIMEOUT_SECS * 1000 /* milliseconds */,
235-
maxBuffer: 5000 * 1024 /* 5MB data max */,
238+
maxBuffer: MAX_BUFFER_SIZE,
239+
// make SURE docker gets the kill signal;
240+
// this signal seems to allow docker to clean
241+
// up after itself to --rm the container, but
242+
// double-check with 'docker ps -a'
243+
killSignal: 'SIGINT'},
244+
postExecHandler.bind(null, res, useJSONP));
245+
}
246+
247+
app.get('/exec_c', exec_cpp_handler.bind(null, false, false));
248+
app.get('/exec_c_jsonp', exec_cpp_handler.bind(null, false, true));
249+
app.get('/exec_cpp', exec_cpp_handler.bind(null, true, false));
250+
app.get('/exec_cpp_jsonp', exec_cpp_handler.bind(null, true, true));
251+
252+
function exec_cpp_handler(useCPP /* use bind first */, useJSONP /* use bind first */, req, res) {
253+
var usrCod = req.query.user_script;
254+
255+
var exeFile;
256+
var args = [];
257+
258+
if (USE_DOCKER_SANDBOX) {
259+
// this needs to match the docker setup in Dockerfile
260+
exeFile = '/usr/bin/docker'; // absolute path to docker executable
261+
args.push('run', '--rm', '--user=netuser', '--net=none', '--cap-drop', 'all', 'pgbovine/opt-cpp-backend:v1',
262+
'/tmp/opt-cpp-backend/run-cpp-backend.sh',
263+
usrCod,
264+
useCPP ? 'cpp' : 'c');
265+
} else {
266+
assert(false);
267+
// must use Docker
268+
}
269+
270+
child_process.execFile(exeFile, args,
271+
{timeout: CPP_TIMEOUT_SECS * 1000 /* milliseconds */,
272+
maxBuffer: MAX_BUFFER_SIZE,
236273
// make SURE docker gets the kill signal;
237274
// this signal seems to allow docker to clean
238275
// up after itself to --rm the container, but
@@ -241,6 +278,8 @@ function exec_ruby_handler(useJSONP /* use bind first */, req, res) {
241278
postExecHandler.bind(null, res, useJSONP));
242279
}
243280

281+
282+
244283
function executePython(pyVer, req, res) {
245284
var parsedOptions = JSON.parse(req.query.options_json);
246285

@@ -277,7 +316,7 @@ function executePython(pyVer, req, res) {
277316

278317
child_process.execFile(exeFile, args,
279318
{timeout: TIMEOUT_SECS * 1000 /* milliseconds */,
280-
maxBuffer: 5000 * 1024 /* 5MB data max */,
319+
maxBuffer: MAX_BUFFER_SIZE,
281320
// make SURE docker gets the kill signal;
282321
// this signal seems to allow docker to clean
283322
// up after itself to --rm the container, but

0 commit comments

Comments
 (0)