Question: I am using Popen to run a command but I don't know how I can write a callback that gets called once the command is finished. Any idea?

Thanks.
Bin

Answer: 
[Flyweight pattern in Python](http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html#flyweight)? (appears to be broken, [Internet Archive version](http://web.archive.org/web/20090619190842/http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html#flyweight))

Edit: [Another flyweight example in Python](http://push.cx/2006/python-flyweights).
The easiest way is probably to use builtin lru\_cache from functools on `__new__`.

```
import functools

class Person:
    gender = 'unknown'
    @functools.lru_cache(maxsize=None)
    def __new__(cls, full_name):
        names = first, last = full_name.split()
        for subclass in cls.__subclasses__():
            if first in subclass.names:
                cls = subclass
        self = super().__new__(cls)
        self.first, self.last = names
        return self

class Woman(Person):
    gender = 'female'
    names = {*'Mary Linda Susan'.split()}

class Man(Person):
    gender = 'male'
    names = {*'Tom Dick Harry'.split()}

```