I created my telegram bot, and it's running successfully, but I need to keep it running till I closed my PC
You have to run it on a server. You can deploy it on Heroku for free (https://www.heroku.com/).
If you want to run it on your own computer (i.e. not on a server such as AWS or Heroku), you could look to daemonize your application. The easiest would be to use python-daemon.
Related
I regularly have Python scripts that take up to 8+ hours to complete that I want to run on a remote server. However, I don't want to go through the hassle of setting up a server, setting an environment, running the script and shutting down the server after the script is done every time.
Ideally, I'm looking for a CLI product like Heroku that spins up a server, runs the script in an environment and shuts down the server after the script is done.
AWS Lambda functions sound close to what I'm looking for, but they have a runtime limit. Are there other solutions that would fit these criteria?
Thanks!
This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 1 year ago.
I am new to dash app development and created a app which is running in the linux server. It is available to all users in our intranet only when I trigger and online. Once I logoff it is not accessible. How to schedule the app to run continuously even when I am offline. Any responses would be appreciated.
currently it is serving with below command
python app.py
I cant deploy in Heroku due to security restrictions. Docker also unavailable. Any other option would be appreciated.
Regards,
Sudheer
From this description, I guess that you
SSH into the server
Run python app.py
At this point, the app is available
Log off from the SSH connection (e.g. exit command)
At this point, the app is not available any more
If so, this is because the command you run during the SSH session will be terminated when you log off from the session.
There are several ways to keep your app running after you log off. For example,
Run nohub python app.py &.
Run tmux and run python app.py in the tmux window. Then Ctrl+b+d to close the tmux window.
In either way, the app will keep running after you log off from the SSH connection. If my guess about your situation is wrong, please elaborate on your situation more in detail. For example, tell us the series of command you run and what happens with them.
In particular, the term "offline" is not clear in this context. If you are completely offline and not connected even to the intranet, then there is no chance that you can use the app running on the server.
I recently made a music bot in my discord server but the problem I have is that I have to turn on the bot manually etc. and it goes offline when I turn off my computer. How can I make the bot stay online at all times, even when I'm offline?
You need to run the python script on a server, e.g. an EWS linux instance.
To do that you would need to install python on the server and place the script in the home directory and just run it via a screen.
Use a Raspberry Pi with an internet connection. Install all necessary components and then run the script in its terminal. Then, you can switch off the monitor and the bot will continue running. I recommend that solution to run the bot 24/7. If you don't have a Raspberry Pi, buy one (they're quite cheap), or buy a server to run the code on.
I created a droplet that runs a flask application. My question is when I ssh into the droplet and restart the apache2 server, do I have to keep the console open all the time (that is I should not shut down my computer) for the application to be live?
What if I have a dynamic application that runs scripts in the background, do I have to keep the console open all the time for the dynamic parts to work?
P.S:
there's a similar question in SO about a NodeJs app but some parts of the answer they provided are irrelevant to my Flask app.
You can use the "screen" command to mantain the sesion open.
please see https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/
In my opinion it is not a good practice to use remote computers for the development stage unless you don't have an other option. If you want to make your application available after logging out from the ssh console, screen works, but it still a workaround.
I would suggest taking a look at this great tutorial on how to daemonize flask applications with Gunicorn+Nginx.
You needn't keep the console on, the app will still running after you close the console on your computer. But you may need to set a log to monitor it.
I have developed a simple python twitter bot which periodically executes various functions using the following libraries:
TwitterFollowBot==2.0.2
schedule==0.3.2
The application works fine when I execute it on my computer, and I wanted to migrate it to Heroku so it could run independently. Upon executing it on Heroku it works as it should for 60 seconds before timing out:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
After researching this, I found out that Heroku dynamically switches ports and my application must continuously specify which port it should run on. From another thread I read that a possible solution required me to alter my Procfile, so I appended the PORT variable to the end:
Procfile: web: python app.py $PORT
This had no effect so I tried it again with ${PORT},
And I also tried switching web: with bot: (which stopped my application from executing properly)
I found other solutions to this issue which worked for node, or python applications using Django, Flask, etc... However, I was unable to find a solution for just a simple .py application. Is this even possible? Or should I create my app with Flask and attempt one of the other fixes?
If it doesn't provide any web content then you don't need to run a web process - call it something else like bot and then do:
heroku ps:scale web=0
heroku ps:scale bot=1
and you won't get any more R10s.