-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinterpreterLanguage.py
More file actions
55 lines (48 loc) · 1.96 KB
/
interpreterLanguage.py
File metadata and controls
55 lines (48 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#-*- coding: utf8 -*-
import dockerContainer
def getVolumnPath(S):
L = S.split(':')
containerVolumn = L[1]
if containerVolumn[len(containerVolumn)-1] != '/':
containerVolumn = containerVolumn + '/'
hostVolumn = L[0]
if hostVolumn[len(hostVolumn)-1] != '/':
hostVolumn = hostVolumn + '/'
return (hostVolumn, containerVolumn)
def run(runName, volumn, option='', intpName='python', imageName='baekjoon/onlinejudge-gcc:4.8', memoryLimit=128, memorySwapLimit=256, stdinName='stdin.txt', timeLimit=5, logger=None):
(hostVolumn, containerVolumn) = getVolumnPath(volumn)
#Run
command = "-v %s --net none --memory %sm --memory-swap %sm %s sh -c '%s %s %s < %s'" % (volumn, str(memoryLimit), str(memorySwapLimit), imageName, intpName, option, runName, containerVolumn+stdinName)
logger.debug(command)
D = dockerContainer.execute(command, timeLimit, logger)
exitCode = D['exitcode']
if logger is not None:
logger.info('Run done. (exit code: %s)' % str(exitCode))
res = {}
if exitCode == 0:
res['state'] = 'success'
res['stdout'] = D['stdout']
res['stderr'] = D['stderr']
elif D['state'] == 'tle':
res['state'] = 'tle'
res['stdout'] = ''
res['stderr'] = 'Running time limit exceeded.'
elif exitCode == 137:
res['state'] = 'error'
res['stdout'] = ''
res['stderr'] = 'Memory limit exceeded.'
elif 'docker' not in D['stderr']:
res['state'] = 'error'
res['stdout'] = D['stdout']
res['stderr'] = D['stderr']
if logger is not None:
logger.info('Exception while running(may due to user): ' + res['stderr'])
else:
res['state'] = 'error'
res['stdout'] = ''
res['stderr'] = 'Server error.'
if logger is not None:
logger.critical('Error while running: ' + res['stderr'])
else:
print 'Error while running: ' + res['stderr']
return res