A Tale of Two Stars

less than 1 minute read

Foo
Photo by Michele Diodati/Medium.

It happened inside a Python universe. Two stars, sun and proxima_centauri, wanted to hang out together in a parallel universe.

class Universe(object):
    def __init__(self):
        pass 
        
class Star(object):
    def __init__(self, star_name, universe):
        self.name = star_name
        self._universe = universe

universe = Universe()
sun = Star(star_name='sun',
             universe=universe)
proxima_entauri = Star(star_name='Proxima Centauri',
             universe=universe)

First, they tried to pickle themselves seperately. They couldn’t find each other.

sun_parallel = pickle.loads(pickle.dumps(sun))
proxima_entauri_parallel = pickle.loads(pickle.dumps(proxima_entauri))

>>>print('universe of parallel sun:', id(sun_parallel._universe))
>>>print('universe of parallel proxima entauri:', id(proxima_entauri_parallel._universe))
universe of parallel sun: 139927156407168
universe of parallel proxima entauri: 139927156407072

Then they decided to do it together. They reunited.

sun_parallel, proxima_entauri_parallel = pickle.loads(pickle.dumps([sun, proxima_entauri])) 

>print('universe of parallel sun:', id(sun_parallel._universe))
>print('universe of parallel proxima entauri:', id(proxima_entauri_parallel._universe))
universe of parallel sun: 140287996428144
universe of parallel proxima entauri: 140287996428144

It’s a true story about AtomGroup.

Updated: