{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Autoreload problem any class\n", "this notebook reproduces the failure of autoreload for any library on its update after the notebook has started, which breaks it. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "\n", "import sys, pickle\n", "\n", "file = \"mytestclass.py\"\n", "\n", "text = \"\"\"\n", "class Test():\n", " def __init__(self):\n", " self.ok = 1\n", "\"\"\"\n", "with open(\"mytestclass.py\",\"w\") as f: f.write(text)\n", "\n", "from mytestclass import *\n", "test = Test()\n", "\n", "# works\n", "p = pickle.dumps(test)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# touch forces autoreloader to reload the library file\n", "!echo touch $file\n", "!touch $file" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# now it fails\n", "p = pickle.dumps(test)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# cleanup\n", "!rm $file " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 2 }