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

Reload to clear module-level variables between games #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cai-lw
Copy link

@cai-lw cai-lw commented May 23, 2021

Mitigates #58 by forcing to reload the module and reset its global variables (See https://docs.python.org/3/library/importlib.html#importlib.reload)

Confirmed that this fix makes the code in #58 no longer work.

However, there are still ways to get around, and I don't think a complete fix is possible. To prevent this completely we may have to rely on manual inspection.

Mitigates carykh#58 by forcing to `reload` the module and reset its global variables (See https://docs.python.org/3/library/importlib.html#importlib.reload)

Confirmed that this fix makes the code in carykh#58 no longer work.

However, there is still ways to get around, and I don't think a complete fix is possible. To prevent this completely we may have to rely on manual inspection.
@cai-lw
Copy link
Author

cai-lw commented May 23, 2021

The following code can still retain variables in MyMemory class between games.

import random

def strategy(history, memory):
    round = history.shape[1] + 1
    if round == 1:
        # This should never be 1
        print(MyMemory.test)
        return 1, MyMemory
    mem = memory
    mem.test = 1
    return 1, mem

try:
    MyMemory
except NameError:
    class MyMemory:
        test = 0

@zebarnabe zebarnabe mentioned this pull request May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant