Skip to content

Instantly share code, notes, and snippets.

@sergei-mironov
Last active October 30, 2019 21:14
Show Gist options
  • Save sergei-mironov/467422ce50f1e6f298d77a8447496d38 to your computer and use it in GitHub Desktop.
Save sergei-mironov/467422ce50f1e6f298d77a8447496d38 to your computer and use it in GitHub Desktop.
minimal.py
# Instructions
# 1. Load this file in IPython
# 2. call `run()`
# 3. Interrupt it with Ctrl+C
# 4. See no global state changed
from typing import Any,Optional
from time import sleep
class Model:
state:Any
def train(m:Model)->None:
m.state = 0
print('Hit Ctrl+C to interrupt "training". Check out (the absence of) M.state')
while True:
m.state = m.state + 1
print('.', end='', flush=True)
sleep(1)
M:Optional[Model]=None
def run():
global M
M=Model()
train(M)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment