From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,NO_DNS_FOR_FROM, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from [192.168.1.2] (unknown [101.128.126.135]) by gnuweeb.org (Postfix) with ESMTPSA id 615337E426; Tue, 3 Jan 2023 12:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1672748229; bh=8CkOuX6Os8h69uWNL+vtBdAyxsZ+kYux1j+apk3Ne1c=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=VzCUefukkO4RsnSo6srf02vZ3viQa/FknF46yMjNUq/PbVz8II/JDPhtgF3u3GOUz b0VG9yVwIsAUMuk2heI/zS1XOWgI7KomT2CEzgEYuzPwLMYkIb4Mf+xGvMaewXSKUF a6Rm6tvby6jLChDP8gEKppixHO7GlLw+fREdfegH681nnvHU5AlIK+ovuttONjrFJi fH0OjyLGtmYZEZ8LTw7X8oe3xdkAA7nXeUvmALX2nrOF1cSHMRVDb9U29QQ13fmbYy k2uFlRrZwIMVWaGKH2HbBk8Gvmxv62jDjWEEQ39tPOh2CwGDFC/SrA4kbpWABXYhC1 A1IfXBKuBF4rQ== Message-ID: Date: Tue, 3 Jan 2023 19:17:04 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v1 03/13] refactor(telegram)!: Ensure the Telegram bot has been started Content-Language: en-US To: Ammar Faizi Cc: Alviro Iskandar Setiawan , GNU/Weeb Mailing List References: <20230103063641.1680-1-kiizuha@gnuweeb.org> <20230103063641.1680-4-kiizuha@gnuweeb.org> <5fa120d7-32ab-b560-0c8f-0da64546cf0b@gnuweeb.org> From: Muhammad Rizki In-Reply-To: <5fa120d7-32ab-b560-0c8f-0da64546cf0b@gnuweeb.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: On 03/01/2023 13.54, Ammar Faizi wrote: > On 1/3/23 1:36 PM, Muhammad Rizki wrote: >> @@ -58,9 +59,11 @@ def main(): >>           scraper=Scraper(), >>           mutexes=BotMutexes() >>       ) >> -    sched.start() >> + >> +    client.start() >>       bot.run() >> -    client.run() >> +    idle() >> +    client.stop() > > I agree to have an 'idle()' call, but it addresses a different issue > w.r.t. the patch subject. Please split the 'idle()' patch into a > separate patch. > No, we should use this method rather than `client.run()`. Why? because at the previous commit, we use `client.run()` after the `bot.run()` which is the `bot` here is running first before the Telegram bot is started/connect to the Telegram MTProto API, previous commit: sched.start() bot.run() <- we listen for new emails, if error may happen, the listener will send the log file which is require to interact with the Telegram API. client.run() <- The client is late to start/connect to the Telegram API. So, my solutions is to use this method: client.start() <- We start/connect to the Telegram API first. bot.run() <- Then, we listen for new emails, if error may happen, the bot is already connected to the Telegram API to send the log file. idle() <- We idle the bot to keep interact with the Telegram API. client.stop() <- Stopped when CTRL + C or SIGINT. What do you think? > My understanding is that the reason for the 'idle()' call is to make the > program gracefully exits when it's interrupted (e.g., SIGINT with > CTRL + C), then you have a chance to call 'client.stop()', which could > be a necessary cleanup to stop the app. > > Is my understanding correct? > Yes.