Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursion with error handling doesn't work #104

Open
jay20162016 opened this issue Apr 18, 2020 · 1 comment
Open

Recursion with error handling doesn't work #104

jay20162016 opened this issue Apr 18, 2020 · 1 comment
Labels
engine engine-breaker-$$$ Winner of the Battlehack 2020 engine breaker prize!

Comments

@jay20162016
Copy link

Running this code:

def turn():
    """
    MUST be defined for robot to run
    This function will be called at the beginning of every turn and should contain the bulk of your robot commands
    """
    try:
        turn()
    except RecursionError:
        pass

will result in (these logs are truncated for briefness)

Traceback (most recent call last):
  File "bot.py", line 33, in turn
  File "bot.py", line 34, in turn
NameError: name 'RecursionError' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bot.py", line 33, in turn
  File "bot.py", line 34, in turn
NameError: name 'RecursionError' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jayjay/.local/lib/python3.7/site-packages/battlehack20/engine/container/runner.py", line 222, in do_turn
    exec(self.locals['turn'].__code__, self.globals, self.locals)
  File "bot.py", line 34, in turn
NameError: name 'RecursionError' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jayjay/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/Users/jayjay/.local/lib/python3.7/site-packages/battlehack20/engine/container/runner.py", line 23, in run
    self.runner.do_turn()
  File "/Users/jayjay/.local/lib/python3.7/site-packages/battlehack20/engine/container/runner.py", line 224, in do_turn
    self.error_method(traceback.format_exc(limit=5))
  File "/Users/jayjay/anaconda3/lib/python3.7/traceback.py", line 167, in format_exc
    return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
  File "/Users/jayjay/anaconda3/lib/python3.7/traceback.py", line 121, in format_exception
    type(value), value, tb, limit=limit).format(chain=chain))
  File "/Users/jayjay/anaconda3/lib/python3.7/traceback.py", line 497, in __init__
    _seen=_seen)
  File "/Users/jayjay/anaconda3/lib/python3.7/traceback.py", line 497, in __init__
    _seen=_seen)
  File "/Users/jayjay/anaconda3/lib/python3.7/traceback.py", line 497, in __init__
    _seen=_seen)
  [Previous line repeated 493 more times]
RecursionError: maximum recursion depth exceeded

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jayjay/anaconda3/lib/python3.7/threading.py", line 890, in _bootstrap
    self._bootstrap_inner()
  File "/Users/jayjay/anaconda3/lib/python3.7/threading.py", line 936, in _bootstrap_inner
    (self.name, _format_exc()), file=_sys.stderr)
  File "/Users/jayjay/anaconda3/lib/python3.7/traceback.py", line 167, in format_exc
    return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
  File "/Users/jayjay/anaconda3/lib/python3.7/traceback.py", line 121, in format_exception
    type(value), value, tb, limit=limit).format(chain=chain))
  File "/Users/jayjay/anaconda3/lib/python3.7/traceback.py", line 497, in __init__
    _seen=_seen)
  File "/Users/jayjay/anaconda3/lib/python3.7/traceback.py", line 497, in __init__
    _seen=_seen)
  File "/Users/jayjay/anaconda3/lib/python3.7/traceback.py", line 497, in __init__
    _seen=_seen)
  [Previous line repeated 494 more times]
RecursionError: maximum recursion depth exceeded
^CTraceback (most recent call last):
  File "run.py", line 112, in <module>
    play_all(delay = float(args.delay), keep_history = args.raw_text, real_time = not args.debug)
  File "run.py", line 66, in play_all
    game.turn()
  File "/Users/jayjay/.local/lib/python3.7/site-packages/battlehack20/engine/game/game.py", line 63, in turn
    robot.turn()
  File "/Users/jayjay/.local/lib/python3.7/site-packages/battlehack20/engine/game/robot.py", line 60, in turn
    self.runner.run()
  File "/Users/jayjay/.local/lib/python3.7/site-packages/battlehack20/engine/container/runner.py", line 237, in run
    self.wrapper.join()
  File "/Users/jayjay/anaconda3/lib/python3.7/threading.py", line 1044, in join
    self._wait_for_tstate_lock()
  File "/Users/jayjay/anaconda3/lib/python3.7/threading.py", line 1060, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
KeyboardInterrupt
^CException ignored in: <module 'threading' from '/Users/jayjay/anaconda3/lib/python3.7/threading.py'>
Traceback (most recent call last):
  File "/Users/jayjay/anaconda3/lib/python3.7/threading.py", line 1308, in _shutdown
    lock.acquire()
KeyboardInterrupt
@spipm
Copy link

spipm commented Apr 21, 2020

Building on this:
The following causes an actual stack overflow:

def turn():
    try:
        turn()
    except:
        turn()

-> "Fatal Python error: Cannot recover from stack overflow."

@arvid220u arvid220u added engine-breaker-$$$ Winner of the Battlehack 2020 engine breaker prize! and removed 🤑? labels Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine engine-breaker-$$$ Winner of the Battlehack 2020 engine breaker prize!
Projects
None yet
Development

No branches or pull requests

3 participants