diff --git a/docs/PyHEP_2021_workshop_presentation/demo.ipynb b/docs/PyHEP_2021_workshop_presentation/demo.ipynb index d0eb7a2..0f4e960 100644 --- a/docs/PyHEP_2021_workshop_presentation/demo.ipynb +++ b/docs/PyHEP_2021_workshop_presentation/demo.ipynb @@ -1,5 +1,27 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "eb25332d", + "metadata": {}, + "source": [ + "# Before you start\n", + "\n", + "To run this notebook you first have to:\n", + "1. Install the `progressreporting` package following the instructions [here](https://github.com/SengerM/progressreporting).\n", + "2. [Create a Telegram bot](https://core.telegram.org/bots#3-how-do-i-create-a-bot) and have in hand its token and also the ID of the chat to which you want to send the messages (basic tutorial [here](https://github.com/SengerM/progressreporting#creating-a-bot), otherwise just google it)." + ] + }, + { + "cell_type": "markdown", + "id": "eef4b1d4", + "metadata": {}, + "source": [ + "# Normal execution with no errors\n", + "\n", + "Import everything:" + ] + }, { "cell_type": "code", "execution_count": null, @@ -11,19 +33,17 @@ "from data_processing_bureaucrat.Bureaucrat import TelegramReportingInformation # Here I store the token of the bot, NEVER make it public!\n", "import time\n", "\n", - "MAX_K = 99999\n", - "SLEEP_PER_LOOP = 3e-4 # Seconds.\n", + "MAX_K = 999\n", + "SLEEP_PER_LOOP = 3e-2 # Seconds.\n", "REPORTING_TIME = 5 # Seconds." ] }, { "cell_type": "markdown", - "id": "eef4b1d4", + "id": "be7cec99", "metadata": {}, "source": [ - "# Normal execution with no errors\n", - "\n", - "Let's see how it works when there are no errors." + "You will not need the `TelegramReportingInformation`, this is just a private repo I have to store both the token and the chat ID of my bot. **Never make the token public to the world!** If you make it public, it will not be long until the world stoles your bot (already happened to me)." ] }, { @@ -43,7 +63,7 @@ " for k in range(MAX_K):\n", " # Do some stuff...\n", " time.sleep(SLEEP_PER_LOOP)\n", - " reporter.update(1) # 1 means 1/MAX_K completed." + " reporter.update(1) # 1 means 1/MAX_K completed. After REPORTING_TIME it will send a message." ] }, { @@ -69,9 +89,9 @@ " for k in range(MAX_K):\n", " # Do some stuff...\n", " time.sleep(SLEEP_PER_LOOP)\n", - " if k > 22222:\n", + " if k > 333:\n", " raise RuntimeError('Unexpected things can happen!')\n", - " reporter.update(1) # 1 means 1/MAX_K completed." + " reporter.update(1)" ] }, { @@ -114,7 +134,17 @@ " for k in range(MAX_K):\n", " # Do some stuff...\n", " time.sleep(SLEEP_PER_LOOP)\n", - " reporter.update(1) # 1 means 1/MAX_K completed." + " reporter.update(1)" + ] + }, + { + "cell_type": "markdown", + "id": "6955d1e7", + "metadata": {}, + "source": [ + "The function `function_with_reporting_loop` is just needed for the `multiprocessing` package. Usually each instance of `TelegramProgressReporter` is runing in different scripts/different computers.\n", + "\n", + "Now we just run 3 instances simultaneously:" ] }, {