Hi, I need some help here.
I have implemented iterative deepening and use signal.alarm
to stop the deepening process after some time. The issue at hand is, that Python does not
catch the Exception all the time. Please refer to the code below.
The code I have written is called by another python program built from tournament masters,
but they do not use the signal
library. Maybe the multiprocessing library is using signal internally?
I have also made sure, that I use my own Exception-type (TimeoutException
).
For whatever reason my Exception is not handled sometimes (most of the time the code works),
even tho “YES” was printed out (meaning the handler has been called).
Here is a (simplified version) of my code:
“`python
def iterative_deepening(my_gs): signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(1) depth = 2 s, m = score_nega_max(my_gs, depth, dict()) try: while 1: depth += 1 print(depth) s, m = score_nega_max(my_gs, depth, dict()) except TimeoutException: print(“Stop iterative deepening.”) return (m,s,depth – 1)
def timeouthandler(*): print(“YESS.”) # For debugging purposes. raise TimeoutException(“Time out iterative deepening.”)
class TimeoutException(Exception): pass “`
I appreciate every help.
PS: I use Python 3.13.1.
E: Formatting.
submitted by /u/two-horned
[link] [comments]
r/learnpython Hi, I need some help here. I have implemented iterative deepening and use signal.alarm to stop the deepening process after some time. The issue at hand is, that Python does not catch the Exception all the time. Please refer to the code below. The code I have written is called by another python program built from tournament masters, but they do not use the signal library. Maybe the multiprocessing library is using signal internally? I have also made sure, that I use my own Exception-type (TimeoutException). For whatever reason my Exception is not handled sometimes (most of the time the code works), even tho “YES” was printed out (meaning the handler has been called). Here is a (simplified version) of my code: “`python def iterative_deepening(my_gs): signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(1) depth = 2 s, m = score_nega_max(my_gs, depth, dict()) try: while 1: depth += 1 print(depth) s, m = score_nega_max(my_gs, depth, dict()) except TimeoutException: print(“Stop iterative deepening.”) return (m,s,depth – 1) def timeouthandler(*): print(“YESS.”) # For debugging purposes. raise TimeoutException(“Time out iterative deepening.”) class TimeoutException(Exception): pass “` I appreciate every help. PS: I use Python 3.13.1. E: Formatting. submitted by /u/two-horned [link] [comments]
Hi, I need some help here.
I have implemented iterative deepening and use signal.alarm
to stop the deepening process after some time. The issue at hand is, that Python does not
catch the Exception all the time. Please refer to the code below.
The code I have written is called by another python program built from tournament masters,
but they do not use the signal
library. Maybe the multiprocessing library is using signal internally?
I have also made sure, that I use my own Exception-type (TimeoutException
).
For whatever reason my Exception is not handled sometimes (most of the time the code works),
even tho “YES” was printed out (meaning the handler has been called).
Here is a (simplified version) of my code:
“`python
def iterative_deepening(my_gs): signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(1) depth = 2 s, m = score_nega_max(my_gs, depth, dict()) try: while 1: depth += 1 print(depth) s, m = score_nega_max(my_gs, depth, dict()) except TimeoutException: print(“Stop iterative deepening.”) return (m,s,depth – 1)
def timeouthandler(*): print(“YESS.”) # For debugging purposes. raise TimeoutException(“Time out iterative deepening.”)
class TimeoutException(Exception): pass “`
I appreciate every help.
PS: I use Python 3.13.1.
E: Formatting.
submitted by /u/two-horned
[link] [comments]