Why does the error occur: repl process died unexpectedly:
My code:
def restart_script():
"""Function to restart the script"""
print("Restarting script...")
# Save any data here if needed
# Then exit
exit()
if __name__ == "__main__":
# Schedule to run the function every hour
schedule.every(5).seconds.do(restart_script)
# Keep the script running
while True:
schedule.run_pending()
time.sleep(1)
Hereās the problem: exit()
sends a kill signal and thus ends the program at once. A small side effect is that message. Just take that out or move it to a different spot. Anytime exit()
is run, it will do that. Also did you know we have a #code-help category? I moved this to #code-help:python.
1 Like
Instead exit made a condition, but now it exits and doesnāt start
def restart_script():
"""Function to restart the script"""
print("Restarting script...")
# Save any data here if needed
if __name__ == "__main__":
# Set the maximum number of iterations
max_iterations = 10
num_iterations = 0
# Schedule to run the function every hour
schedule.every(5).seconds.do(restart_script)
# Keep the script running for a maximum number of iterations
while num_iterations < max_iterations:
schedule.run_pending()
time.sleep(1)
num_iterations += 1
Please format your code to make it easier to read. Right now Iām having a hard time reading it with some of it formatted and some of it not. Also some of it is not indented which is bad in Python.
When is name
defined? Is the while
loop a part of the if
statement? Iām not exactly sure how your code works because itās not all formatted.
```python
YOUR CODE HERE
```
The above will format your code for you. Please use it.
1 Like
Please help me with the following:
- Why do we need the
if
statement? Now that youāre already using boolean logic in your while
loop I think itās unnecessary.
- Is this Repl āAlways Onā? If not then this code probably wonāt do you any good.
- Do you mind providing the link to the Repl?
Because if you share the repl we can see the code and hep better.
1 Like
āscheduleā is not defined. Is that imported somewhere else in your code? This is why we like to have the link to the Repl.
import threading
import schedule
import time
from dotenv import load_dotenv
load_dotenv()
import telebot
import openai
import logging
import sqlite3
from datetime import datetime
Can you please give me a goal here? Iāve fixed some problems here but the thing canāt run forever because Python has a maximum recursion limit. If you would please tell me what your goal is and include the link to your Repl I could be of more assistance.
https://replit.com/@hmatvej49/Telegram-bot-na-osnovie-Chat-GPT#main.py
There is also an error: An error occurred: āmessagesā is a required property
Using OpenAI is above my head. Sorry, but I cannot help you any further here.
Help me please, I do not know what to do
This looks like a script you copied from somewhere. So probably there are instructions and an explanation of what it does.
Btw it Looks like an always on process. Realise that even always-on repls actually go to sleep. Also recursion in python has limits.
name is a special variable in Python, maybe thatās what you were asking about?
Some info about name
Those. restart every hour can not be configured? Then what about the error: An error occurred: āmessagesā is a required property
please help me i dont know what to do
React on what we suggest, try to reduce recursion for example. Tell us what you try to do (always on, wake up, etc)
1 Like