File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
web/problems/templates/python Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -209,7 +209,9 @@ def update_attempts(old_parts, response):
209209 ] = "{{ token }}"
210210 try :
211211 {{ part .validation | default :"pass" | indent :" " | safe }}
212- except :
212+ except TimeoutError :
213+ Check .error ("Dovoljen čas izvajanja presežen" )
214+ except Exception :
213215 Check .error (
214216 "Testi sprožijo izjemo\n {0}" ,
215217 "\n " .join (traceback .format_exc ().split ("\n " ))[:- 2 ],
Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ def readline(self, size=None):
1414 return line
1515
1616
17+ class TimeoutError (Exception ):
18+ pass
19+
20+
1721class Check :
1822 parts = None
1923 current_part = None
@@ -394,3 +398,21 @@ def set_stringio(stringio):
394398 else :
395399 with Check .set (stringio = stringio ):
396400 yield
401+
402+ @staticmethod
403+ @contextmanager
404+ def time_limit (timeout_seconds = 1 ):
405+ from signal import SIGINT , raise_signal
406+ from threading import Timer
407+
408+ def interrupt_main ():
409+ raise_signal (SIGINT )
410+
411+ timer = Timer (timeout_seconds , interrupt_main )
412+ timer .start ()
413+ try :
414+ yield
415+ except KeyboardInterrupt :
416+ raise TimeoutError
417+ finally :
418+ timer .cancel ()
You can’t perform that action at this time.
0 commit comments