Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from piterator-org/dev
Browse files Browse the repository at this point in the history
Bump version number to v0.8.0
  • Loading branch information
wxh06 authored Mar 27, 2020
2 parents 2b23ed6 + fe6ae7c commit ae5b060
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
</p>

# dockerjudge
[![Build Status](https://www.travis-ci.org/wangxinhe2006/dockerjudge.svg)](https://www.travis-ci.org/wangxinhe2006/dockerjudge)
[![CodeCov](https://codecov.io/gh/wangxinhe2006/dockerjudge/graph/badge.svg)](https://codecov.io/gh/wangxinhe2006/dockerjudge)
[![Build Status](https://www.travis-ci.org/piterator-org/dockerjudge.svg)](https://www.travis-ci.org/piterator-org/dockerjudge)
[![CodeCov](https://codecov.io/gh/piterator-org/dockerjudge/graph/badge.svg)](https://codecov.io/gh/piterator-org/dockerjudge)
[![Python Version](https://img.shields.io/pypi/pyversions/dockerjudge.svg)](https://www.python.org/downloads/)
[![GitHub pre-release](https://img.shields.io/github/release-pre/wangxinhe2006/dockerjudge.svg)](https://github.com/wangxinhe2006/dockerjudge/releases)
[![GitHub pre-release](https://img.shields.io/github/release-pre/piterator-org/dockerjudge.svg)](https://github.com/piterator-org/dockerjudge/releases)
[![PyPI](https://img.shields.io/pypi/v/dockerjudge.svg)](https://pypi.org/project/dockerjudge/#history)
[![Wheel](https://img.shields.io/pypi/wheel/dockerjudge.svg)](https://pypi.org/project/dockerjudge/#files)
[![License](https://img.shields.io/github/license/wangxinhe2006/dockerjudge.svg)](LICENSE)
[![License](https://img.shields.io/github/license/piterator-org/dockerjudge.svg)](LICENSE)

A Docker Based Online Judge Engine

Expand All @@ -31,11 +31,11 @@ easy_install dockerjudge
```

### From [GitHub](https://github.com/)
[wangxinhe2006/dockerjudge: A Docker Based Online Judge Engine](https://github.com/wangxinhe2006/dockerjudge)
- HTTPS: `https://github.com/wangxinhe2006/dockerjudge.git`
- SSH: `[email protected]:wangxinhe2006/dockerjudge.git`
[wangxinhe2006/dockerjudge: A Docker Based Online Judge Engine](https://github.com/piterator-org/dockerjudge)
- HTTPS: `https://github.com/piterator-org/dockerjudge.git`
- SSH: `[email protected]:piterator-org/dockerjudge.git`
```sh
git clone https://github.com/wangxinhe2006/dockerjudge.git
git clone https://github.com/piterator-org/dockerjudge.git
cd dockerjudge
python3 setup.py install
```
Expand Down
36 changes: 20 additions & 16 deletions dockerjudge/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'dockerjudge - A Docker Based Online Judge Engine'

import math
from pprint import pprint
import re
import shlex
Expand All @@ -9,7 +10,7 @@
import docker
import ruamel.yaml

__version__ = '0.7.2'
__version__ = '0.8.0'


class Thread(threading.Thread):
Expand Down Expand Up @@ -79,9 +80,11 @@ def _judge(dir, container, commands, ioput, timeout, iofile) -> (str, float):


def judge(settings, source='', tests=[], timeout=1, iofile=(None, None),
callback={}, client=docker.from_env()):
callback={}, split=0, client=docker.from_env()):
'Main judge function'
tests = list(tests)
if not split:
split = len(tests)
container = client.containers.run(settings['image'], detach=True,
network_disabled=True, tty=True)
try:
Expand All @@ -94,21 +97,22 @@ def judge(settings, source='', tests=[], timeout=1, iofile=(None, None),
if compiler.exit_code:
result = [('CE', .0) for test in tests]
else:
threads = []
for i in range(len(tests)):
thread = Thread(target=_judge,
args=(i, container,
(settings.get('before_judging'),
settings['judge'],
settings.get('after_judging')),
tests[i], timeout, iofile),
callback=callback.get('judging'))
thread.start()
threads.append(thread)
result = []
for thread in threads:
thread.join()
result.append(thread.return_value)
for i in range(math.ceil(len(tests) / split)):
threads = []
for j in range(i * split, min((i + 1) * split, len(tests))):
thread = Thread(target=_judge,
args=(j, container,
(settings.get('before_judging'),
settings['judge'],
settings.get('after_judging')),
tests[j], timeout, iofile),
callback=callback.get('judging'))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
result.append(thread.return_value)
return [result, (compiler.output[1] or b'').decode()]
finally:
container.remove(force=True)
Expand Down
20 changes: 20 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from time import time
import unittest

from dockerjudge import judge
Expand Down Expand Up @@ -167,6 +168,25 @@ def judging_callback(id, status, duration):
self.assertEqual(result[0][2][0], 'RE')
self.assertFalse(result[1])

def test_split(self):
t = time()
result = judge({'image': 'gcc:4.8',
'source': 'a.cpp',
'compile': 'g++ a.cpp',
'judge': '%s/a.out'},
r'#include <stdio.h>''\n'
r'int main() {''\n'
r' while (true)''\n'
r' ;''\n'
r'}''\n',
[('', '')] * 3,
3, split=2)
self.assertEqual(result[0][0][0], 'TLE')
self.assertEqual(result[0][1][0], 'TLE')
self.assertEqual(result[0][2][0], 'TLE')
self.assertGreater(time() - t, 6)
self.assertFalse(result[1])


if __name__ == '__main__':
unittest.main()

0 comments on commit ae5b060

Please sign in to comment.