diff --git a/content/10_concurrency.ipynb b/content/10_concurrency.ipynb index 88b581f..1997c4f 100644 --- a/content/10_concurrency.ipynb +++ b/content/10_concurrency.ipynb @@ -117,22 +117,24 @@ "import shutil\n", "\n", "if __name__ == \"__main__\":\n", - " itr_forms = [\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr1_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr2_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr3_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr4_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr5_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr6_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr7_english.pdf\",\n", + " us_forms = [\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/i1040gi.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/i1040tt.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040s.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/fw4.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040es.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/fw9.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/iw9.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f4506t.pdf\"\n", " ]\n", "\n", " target_path = Path(\"static\") / \"concurrency_example\"\n", " shutil.rmtree(target_path, ignore_errors=True)\n", " target_path.mkdir(exist_ok=True, parents=True)\n", "\n", - " for itr_form in itr_forms:\n", - " download_file(itr_form, target_path)\n", + " for form in us_forms:\n", + " download_file(form, target_path)\n", "\n", " print(\"All downloads completed!\")" ] @@ -172,14 +174,16 @@ "import shutil\n", "\n", "if __name__ == \"__main__\":\n", - " itr_forms = [\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr1_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr2_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr3_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr4_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr5_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr6_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr7_english.pdf\",\n", + " us_forms = [\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/i1040gi.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/i1040tt.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040s.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/fw4.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040es.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/fw9.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/iw9.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f4506t.pdf\"\n", " ]\n", "\n", " target_path = Path(\"static\") / \"concurrency_example\"\n", @@ -188,8 +192,8 @@ "\n", " threads = []\n", " \n", - " for itr_form in itr_forms:\n", - " my_thread = threading.Thread(target=download_file, args=(itr_form, target_path))\n", + " for form in us_forms:\n", + " my_thread = threading.Thread(target=download_file, args=(form, target_path))\n", " my_thread.start()\n", " threads.append(my_thread)\n", " \n", @@ -275,14 +279,16 @@ " print(f\"Completing {self.name}\")\n", "\n", "if __name__ == \"__main__\":\n", - " itr_forms = [\n", - " \"https://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr1_english.pdf\",\n", - " \"https://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr2_english.pdf\",\n", - " \"https://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr3_english.pdf\",\n", - " \"https://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr4_english.pdf\",\n", - " \"https://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr5_english.pdf\",\n", - " \"https://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr6_english.pdf\",\n", - " \"https://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr7_english.pdf\",\n", + " us_forms = [\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/i1040gi.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/i1040tt.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040s.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/fw4.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040es.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/fw9.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/iw9.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f4506t.pdf\"\n", " ]\n", "\n", " target_path = Path(\"static\") / \"concurrency_example\"\n", @@ -290,8 +296,8 @@ " target_path.mkdir()\n", "\n", " threads = []\n", - " for itr_form in itr_forms:\n", - " my_thread = DownloaderThread(itr_form, target_path)\n", + " for form in us_forms:\n", + " my_thread = DownloaderThread(form, target_path)\n", " my_thread.start()\n", " threads.append(my_thread)\n", "\n", @@ -317,7 +323,8 @@ "id": "0d5d8d48-5452-4e78-b3b1-98a51720bd6c", "metadata": {}, "source": [ - "## Threads are not good for CPU bound task" + "## Threads are not efficient for CPU bound tasks\n", + "We will cover `multiprocessing` for speeding up such tasks later." ] }, { @@ -804,14 +811,16 @@ "import shutil\n", "\n", "def main():\n", - " itr_forms = [\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr1_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr2_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr3_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr4_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr5_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr6_english.pdf\",\n", - " \"http://incometaxindia.gov.in/forms/income-tax%20rules/2023/itr7_english.pdf\",\n", + " us_forms = [\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/i1040gi.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/i1040tt.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040s.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/fw4.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f1040es.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/fw9.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/iw9.pdf\",\n", + " \"https://www.irs.gov/pub/irs-pdf/f4506t.pdf\"\n", " ]\n", "\n", " target_path = Path(\"static\") / \"concurrency_example\"\n", @@ -819,7 +828,7 @@ " target_path.mkdir(exist_ok=True, parents=True)\n", "\n", " with concurrent.futures.ThreadPoolExecutor() as executor:\n", - " futures = [executor.submit(download_file, itr_form, target_path) for itr_form in itr_forms]\n", + " futures = [executor.submit(download_file, form, target_path) for form in us_forms]\n", " \n", " # Wait for all futures to complete\n", " concurrent.futures.wait(futures)\n", diff --git a/content/11_virtual_environment.ipynb b/content/11_virtual_environment.ipynb index ad74432..77fcf6f 100644 --- a/content/11_virtual_environment.ipynb +++ b/content/11_virtual_environment.ipynb @@ -47,7 +47,8 @@ "\n", "- **Dependency Isolation:** Projects can have different dependencies and package versions without conflicts.\n", "- **Version Compatibility:** Avoid compatibility issues when multiple projects require different package versions.\n", - "- **Easy Cleanup:** You can simply delete the virtual environment folder to clean up dependencies." + "- **Easy Cleanup:** You can simply delete the virtual environment folder to clean up dependencies.\n", + "- **No administrator privileges needed:** You can install packages to a virtual environment without full control of the host environment." ] }, { @@ -145,7 +146,7 @@ "source": [ "## Best Practices\n", "\n", - "- Always use virtual environments for Python projects. Some linux distro have some of the python packages part of the OS and if that get changed then it might break the OS.\n", + "- Use virtual environments whenever you make use of external packages. Some linux distro have some of the python packages part of the OS and if that get changed then it might break the OS.\n", "![](./static/virtual_env_linux.png)\n", "- Use `requirements.txt` to list project dependencies for easy replication.\n", "- Regularly update your Python interpreter and `pip`.\n", @@ -193,4 +194,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/content/14_python_builtin_cli.ipynb b/content/14_python_builtin_cli.ipynb index e536ed9..45e4e8f 100644 --- a/content/14_python_builtin_cli.ipynb +++ b/content/14_python_builtin_cli.ipynb @@ -248,7 +248,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.11.6" } }, "nbformat": 4, diff --git a/content/15_python_toolkit.ipynb b/content/15_python_toolkit.ipynb index d3d9fd0..3375273 100644 --- a/content/15_python_toolkit.ipynb +++ b/content/15_python_toolkit.ipynb @@ -138,4 +138,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +}