Advanced function pickling for Python