I readed a lot of questions here in stackoverflow, but I cannot solve my problem.
I have a simples python script (Only a print('Hello World')) and I'm sending it to Heroku, my files are:
Procfile: (I believe the problem is here)
web: python index.py
heroku logs --tail
2020-05-06T16:06:38.000000+00:00 app[api]: Build started by user <myemail>
2020-05-06T16:07:00.948412+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-06T16:07:00.572714+00:00 app[api]: Release v11 created by user <myemail>
2020-05-06T16:07:00.572714+00:00 app[api]: Deploy 4053de7f by user <myemail>
2020-05-06T16:07:07.099124+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-06T16:07:07.103524+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-06T16:07:07.002972+00:00 app[web.1]: Hello World
2020-05-06T16:07:08.000000+00:00 app[api]: Build succeeded
2020-05-06T16:07:13.797877+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-06T16:07:13.619779+00:00 app[web.1]: Hello World
heroku ts
Free dyno hours quota remaining this month: 550h 0m (100%)
For more information on dyno sleeping and how to upgrade, see:
https://devcenter.heroku.com/articles/dyno-sleeping
=== web (Free): python index.py (1)
web.1: crashed 2020/05/06 13:07:13 -0300 (~ 4m ago)
How we can see, the "Hello World" in log shows that the script runs when I send it to server. But after it, the dyno crashes
in case of Web dyno the application must bind to the port provided by Heroku and defined in the $PORT env variable, where it will receive the incoming requests.
If you need to HTTP traffic try to create a worker node
For example to create a simple Flask app which can receive requests:
from flask import Flask
import os
import logging
try:
app = Flask(__name__)
except Exception as e:
logging.exception("Error at startup")
#app.route('/test')
def test():
logging.info('/test')
return "test Ok"
if __name__ == '__main__':
app.run(debug=False, port=int(os.environ.get("PORT", 5000)), host='0.0.0.0')
Port is set using $PORT on Heroku while locally defaults to 5000
Related
I'm deploying torchserve on heroku free dyno. Deploy works fine but the app isn't running properly.
LOG1:
2022-03-17T02:11:10.352655+00:00 heroku[web.1]: Starting process with command `torchserve --start --ncs --model-store model_store --models squeezenet1_1.mar`
2022-03-17T02:11:11.558957+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2022-03-17T02:11:11.701395+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2022-03-17T02:11:11.896962+00:00 heroku[web.1]: Process exited with status 0
2022-03-17T02:11:12.059922+00:00 heroku[web.1]: State changed from starting to crashed
LOG2:
2022-03-17T05:17:29.472219+00:00 heroku[web.1]: Starting process with command `torchserve --start --ncs --model-store model_store --models squeezenet1_1.mar`
2022-03-17T05:17:30.854303+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2022-03-17T05:17:31.304897+00:00 heroku[web.1]: Process exited with status 0
2022-03-17T05:17:31.364160+00:00 heroku[web.1]: State changed from starting to crashed
Also, my requirements.txt:
-f https://download.pytorch.org/whl/cpu/torch_stable.html
future
psutil
requests
captum
packaging
numpy
cython
wheel
pillow==9.0.1
torch==1.10.0+cpu
torchvision==0.11.1+cpu
torchaudio==0.10.0+cpu
torchtext==0.11.0
torchserve==0.5.3
runtime.txt
python-3.8.12
system.properties
java.runtime.version=1.8.0_322
Problem was torchserve was running in background mode by default.
Adding --foreground to the torchserve command in Procfile fixed this.
(Also, java runtime 11.0.14.1 is required by torchserve)
I created a simple python app on Heroku to launch scrapyd. The scrapyd service starts, but it launches on port 6800. Heroku requires you to bind it the $PORT variable, and I was able to run the heroku app locally. The logs from the process are included below. I looked at a package scrapy-heroku, but wasn't able to install it due to errors. The code in app.py of this package seems to provide some clues as to how it can be done. How can I implement this as a python command to start scrapyd on the port provided by Heroku?
Procfile:
web: scrapyd
Heroku Logs:
2022-01-24T05:17:27.058721+00:00 app[web.1]: 2022-01-24T05:17:27+0000 [twisted.scripts._twistd_unix.UnixAppLogger#info] twistd 21.7.0 (/app/.heroku/python/bin/python 3.10.2) starting up.
2022-01-24T05:17:27.058786+00:00 app[web.1]: 2022-01-24T05:17:27+0000 [twisted.scripts._twistd_unix.UnixAppLogger#info] reactor class: twisted.internet.epollreactor.EPollReactor.
2022-01-24T05:17:27.059190+00:00 app[web.1]: 2022-01-24T05:17:27+0000 [-] Site starting on 6800
2022-01-24T05:17:27.059301+00:00 app[web.1]: 2022-01-24T05:17:27+0000 [twisted.web.server.Site#info] Starting factory <twisted.web.server.Site object at 0x7f1706e3eaa0>
2022-01-24T05:17:27.059649+00:00 app[web.1]: 2022-01-24T05:17:27+0000 [Launcher] Scrapyd 1.3.0 started: max_proc=32, runner='scrapyd.runner'
2022-01-24T05:18:25.204305+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2022-01-24T05:18:25.231596+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-01-24T05:18:25.402503+00:00 heroku[web.1]: Process exited with status 137
You just need to read the PORT environment variable and write it into your scrapyd config file. You can check out this code that does the same.
# init.py
import os
import io
PORT = os.environ['PORT']
with io.open("scrapyd.conf", 'r+', encoding='utf-8') as f:
f.read()
f.write(u'\nhttp_port = %s\n' % PORT)
Source: https://github.com/scrapy/scrapyd/issues/367#issuecomment-591446036
It used to work fine so far both in heroku and locally. Now it only works locally but doesn't work aftter deploying on heroku. This is the log from Heroku:
2021-04-22T17:41:34.000000+00:00 app[api]: Build succeeded
2021-04-22T17:41:37.853181+00:00 heroku[worker.1]: Starting process with command `python3.9.4 dbot.py`
2021-04-22T17:41:38.485331+00:00 heroku[worker.1]: State changed from starting to up
2021-04-22T17:41:39.356992+00:00 app[worker.1]: bash: python3.9.4: command not found
2021-04-22T17:41:39.416346+00:00 heroku[worker.1]: Process exited with status 127
2021-04-22T17:41:39.485205+00:00 heroku[worker.1]: State changed from up to crashed
I have my requirments.txt file with these dependencies included:
git+https://github.com/Rapptz/discord.py
youtube_dl==2020.03.08
pynacl == 1.3.0
colorlog == 4.1.0
And I have this in my procfile:
worker: python3.9.4 dbot.py
As for my knowledge I think it has something do with the python version which I recently updated to 3.9.4
Instead of putting the version of python into the Procfile simply put:
worker: python dbot.py
If you want to specify a python version for your bot create a runtime.txt file with the following format
python-3.9.4
I can't find a solution. I'm hosting a telegram bot in python with the library pyTelegramBotAPI on Heroku, my code works but the script stop running after 1 or 2 hours from a new deployment or a new execution through the console (or some minutes, i don't know the exact timing). Where is the problem? Thanks for the help.
Example of logs on Heroku:
2020-07-15T10:47:40.500384+00:00 app[api]: Starting process with command `python randobot.py` by user ________#gmail.com
2020-07-15T10:47:44.398310+00:00 heroku[run.1085]: State changed from starting to up
2020-07-15T10:47:44.455749+00:00 heroku[run.1085]: Awaiting client
2020-07-15T10:47:44.773283+00:00 heroku[run.1085]: Starting process with command `python\ randobot.py`
2020-07-15T10:47:50.709806+00:00 heroku[run.1085]: Client connection closed. Sending SIGHUP to all processes
2020-07-15T10:47:51.233462+00:00 heroku[run.1085]: Process exited with status 129
2020-07-15T10:47:51.270855+00:00 heroku[run.1085]: State changed from up to complete
Procfile.:
web: python randobot.py
Code randobot.py:
import telebot
import time
import json
bot_token = "____________________________"
bot = telebot.TeleBot(token=bot_token)
...
... Some functions ...
...
while True:
try:
bot.polling(none_stop=True)
except Exception as e:
logger.error(e)
time.sleep(15)
Commands used for the deploy on Heroku with git:
git add .
git commit -m "..."
git push heroku master
Command used the first time on Heroku to run the bot (after the login ecc.):
heroku ps:scale web=1
It works, with (command on the console):
heroku ps:scale worker=1
I've been stuck trying to get my simple bottle app starting when deployed on heroku.
After quite some searching and tinkering I've got a setup that works locally, but not on heroku.
In /app.py:
import bottle
import beaker.middleware
from bottle import route, redirect, post, run, request, hook, template, static_file, default_app
bottle.debug(True)
app = beaker.middleware.SessionMiddleware(bottle.app(), session_opts)
...
# app routes etc, no run()
Then in /Procfile:
web: gunicorn app:app --bind="0.0.0.0:$PORT" --debug
Correct me if I misunderstand how gunicorn works, I understand the "app:app" portion as look in the module (=file) called app.py and use whatever is in variable "app" as your WSIG, yes?
I've checked via $ heroku run bash if $PORT is set, seems ok
The "0.0.0.0" IP I've got from other heroku examples, that should anyway accept any IPs server end, no?
Python dependencies seem to get installed fine
I've got this locally running by setting the $POST variable via an .env file for foreman, everything seems working ok on my setup
Based on this SO question I checked $ heroku ps
=== web (1X): `gunicorn app:app --bind="0.0.0.0:$PORT" --debug`
web.1: crashed 2014/12/24 22:43:00 (~ 1m ago)*)
And $ heroku logs shows:
2014-12-24T20:42:59.235657+00:00 heroku[web.1]: Starting process with command `gunicorn app:app --bind="0.0.0.0:23177" --debug`
2014-12-24T20:43:00.434570+00:00 heroku[web.1]: State changed from starting to up
2014-12-24T20:43:01.813679+00:00 heroku[web.1]: State changed from up to crashed
2014-12-24T20:43:01.803122+00:00 heroku[web.1]: Process exited with status 3
Not sure really how I could get better debugging results either. Somehow the Procfile web process just doesn't seem to work / start, but how can I get info on what's breaking?
Anybody got ideas what's going on here?
P.S.: I'm rather new to heroku, python, bottle & gunicorn :O
What version of gunicorn do you use?
gunicorn 19.1 doesn't write errorlog by default. Try gunicorn --log-file=-.
-R is also useful option to investigate error.
Can you try having just web: gunicorn app:app in your Procfile with nothing else?