Running discord.py on Railway, but print statements are not output as logs.
Although I should be doing stdout with print statements, for some reason they are not output in the log. For example, the following source code does output:
However, when I switch to code that includes discord.py, there is no output. Even if I pasted the above code at the very top, the result was the same. I can't provide all the code for discord.py, but I will provide a part of it. When run on a CentOS 8 environment, the print statements are displayed correctly.
Is there a problem where print statements are not output when using discord.py? Or do I need to set something up? I would appreciate it if you could let me know.
Thank you in advance.
Solution:Jump to solution
but yeah Adam is right, python print statements are buggy in docker environments, there's 3 things you can do
1. what Adam said, flush=True
2. set a service variable
PYTHONUNBUFFERED
= 1
(this is what is done by nixpacks)
3. run python with python -u
instead...9 Replies
Project ID:
f83f8d1f-6778-472e-9271-de7e9f261bb6
f83f8d1f-6778-472e-9271-de7e9f261bb6
Python’s print statements can be buggy, can you try adding flush=True to your statements?
are you building with a dockerfile?
yes, dockerfile is here
FROM python:3.6
WORKDIR /bot
COPY requirements.txt /bot/
RUN pip install -r requirements.txt
COPY . /bot
CMD python main.py
doesn't look like it's doing anything nixpacks wouldn't do by default, try removing your dockerfile and let railway build it with nixpacks
Solution
but yeah Adam is right, python print statements are buggy in docker environments, there's 3 things you can do
1. what Adam said, flush=True
2. set a service variable
PYTHONUNBUFFERED
= 1
(this is what is done by nixpacks)
3. run python with python -u
insteadAs Adam said, I was able to output with flush=True. However, it's a hassle to write this for every print statement.
The method you suggested, setting the environment variable to PYTHONUNBUFFERED = 1, also worked.
Thank you. I will consider this issue resolved now.
glad we could help 🙂