diff options
author | Jayaram R Pai | 2014-09-04 13:23:42 +0530 |
---|---|---|
committer | Jayaram R Pai | 2014-09-04 13:23:42 +0530 |
commit | 87b533642db245fe3c03c9b1fd8220f0f7a195f8 (patch) | |
tree | 43fa11da054d49d638450ee45d55f838c9b1eb27 | |
parent | 6349505c1b9cb638d562bd06a75a26109b106f0d (diff) | |
download | scilab-on-cloud-87b533642db245fe3c03c9b1fd8220f0f7a195f8.tar.gz scilab-on-cloud-87b533642db245fe3c03c9b1fd8220f0f7a195f8.tar.bz2 scilab-on-cloud-87b533642db245fe3c03c9b1fd8220f0f7a195f8.zip |
added timertask
-rw-r--r-- | website/helpers.py | 16 | ||||
-rw-r--r-- | website/views.py | 6 |
2 files changed, 6 insertions, 16 deletions
diff --git a/website/helpers.py b/website/helpers.py index 016f2fd..f137541 100644 --- a/website/helpers.py +++ b/website/helpers.py @@ -1,14 +1,12 @@ -import os -import re -import time -import subprocess +import os, re, sys, time, subprocess from soc.settings import PROJECT_DIR +from timeout import TimerTask def scilab_run(code, token, example_id): #Check for system commands system_commands = re.compile( - 'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|unix_x\(.*\)|unix_s\(.*\)' + 'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|unix_x\(.*\)|unix_s\(.*\)|host|newfun|execstr|ascii|mputl|dir\(\)' ) if system_commands.search(code): return "System Commands not allowed" @@ -36,7 +34,6 @@ def scilab_run(code, token, example_id): file_path = PROJECT_DIR + '/static/tmp/' + token + '.sci' - #thanks @prathamesh920 github #traps even syntax errors eg: endfunton f = open(file_path, "w") f.write('mode(2);\n') @@ -50,11 +47,10 @@ def scilab_run(code, token, example_id): cmd = 'printf "lines(0)\nexec(\'{0}\',2);\nquit();"'.format(file_path) cmd += ' | /home/cheese/scilab-5.4.1/bin/scilab-adv-cli -nw' - output = subprocess.Popen( - cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True - ).communicate()[0] + task = TimerTask(cmd, timeout=10) + output = task.run().communicate()[0] + e = task.wait() - #os.remove(file_path) output = trim(output) data = { 'output': output, diff --git a/website/views.py b/website/views.py index 785337f..050ec92 100644 --- a/website/views.py +++ b/website/views.py @@ -82,9 +82,3 @@ def ajax_execute(request): token = request.POST['csrfmiddlewaretoken'] data = scilab_run(code, token, example_id) return render(request, 'website/templates/ajax-execute.html', data) - - - - - - |