Reputation: 255
I'm currently running a function for multiple process areas of a production facility. Unfortunately, I cannot send the full code as it contains a lot of confidential information from the customer.
Each area is checked with a function in different cells of a ipynb in Jupyter and I ran into an issue were the production for an area is 0 for the given period. My solution is to use sys.exit(0) in the function if the production is 0 for the given period.
This works to stop the cell and print the error. However, I then run into the issue where the other cells below don't run because of the exit command.
Is there any way that you can stop the function from running with a check like the one below and also keep it from interrupting entire your notebook? See the attached image to see what I'm referencing. The code blow is inside the function I'm calling.
if len(df_prod.values()) == 0:
print('There is no data for the given time')
sys.exit(0)
else:
continue
P.S. My apologies if this isn't clear. I'm pretty new to coding and even newer to stackoverflow! Please let me know any best practices or if you need any clarification.
EDIT: The picture below may help clarify.
Image showing the issue. Outputs were hidden from cell 4.
Upvotes: 1
Views: 1079
Reputation: 5955
If you're just trying to run a function until a certain result is achieved, then rather than using sys.exit(0)
to stop running all code just return
from the function so the script can move on to running the next
Upvotes: 1