import time
import threading
import pickle as pk

class Countdown:
    def __init__(self, n):
        self.n = n
        self.thr = threading.Thread(target=self.run)
        self.thr.daemon = True
        self.thr.start()

    def run(self):
        while self.n > 0:
            print('T-minus', self.n)
            self.n -= 1
            time.sleep(5)

    def __getstate__(self):
        return self.n

    def __setstate__(self, n):
        self.__init__(n)

# following experiment involving pickling
# c = Countdown(10)
# print(c.run())

# f = open('cstate.p', 'wb')
# pk.dumbs(c, f)
# f.close()

