Search code examples
pythonpython-telegram-bot

How to deploy multiple Python-Telegram-Bot (s) in local macOS (As a bot server)?


So far I am just simply open 2 sessions(I've got 2 bots so far) in macOS 'Terminal' and run the bots.

May I know if there is better way to make those bots alive? Is that the normal way that most of the people will do in this way?

Like this, once the bot is started, then I will just leave the session here for listening the requests. enter image description here

Thanks all.


Solution

    • Way 1: Run inside docker container
      You need to install docker Desktop at your Mac and run each python script in separate container

      Pros:

      • Modern and correct way to run background processes
      • Running environment independent from local environment

      Cons:

      • You need to install docker
      • You need to know/learn docker
    • Way 2: Run as daemon process inside Linux Virtual Machine [VM]
      You need to install hypervisor (VirtualBox for example) and install Linux on it. After that use it like server for python scripts.

      Pros:

      • Same as 1

      Cons:

      • You need to install hypervisor
      • You need to know Linux and how to daemonize script (using systemd for example)
      • VM need more resources than docker
    • Way 3: Run process in background detached from terminal
      Just run nohup pyton3 /Users/ws_fingear/Documents/workspace/Telegram_Bot/Telegram_Bot_WSFG1.0.py > output.log &. Mark & means that process will be run in background and continue to run even if you close terminal. Output will be printed out inside output.log file

      Pros:

      • Super simple

      Cons:

      • Bad way for production environment
      • Can't control or stop running process properly

    I guess, you looking for way 3.

    Also you can use syncthing on Mac OS to run script as daemon locally