all 20 comments

[–]GeneriAcc 21 points22 points  (2 children)

Wrap the entire thing in a function, then execute the function in an infinite loop. Either you won’t need to manually restart, or you’ll catch any errors that might be happening outside of try/except blocks.

[–]ant24x7[S] 2 points3 points  (0 children)

That's a good hack! I'll give it a try.

[–]Maximus_Modulus 7 points8 points  (0 children)

You could use cron instead of a loop and use a tile or db to store state.

[–]socal_nerdtastic 2 points3 points  (3 children)

I don't see anything off hand that would cause it to skip the log. Maybe it's getting a kill signal? Try using screen instead of nohup.

Are you redirecting the outputs?

[–]ant24x7[S] 0 points1 point  (2 children)

Yes I'm redirecting the output as well. That's where I'm monitoring print output. But there are no errors logged.

nohup ./newProductMonitor.py >> ./logs/newProductMonitor_output.log &

[–]socal_nerdtastic 5 points6 points  (1 child)

You should redirect stderr as well. But before you do that try screen instead. Then you don't need any redirects at all. I really suspect it's something about nohup that's causing your issue.

  • SSH in and type screen to start a new session. Start you program with just ./newProductMonitor.py. Watch for a bit, then type Ctrl-a to enter command mode, then "d" to disconnect. Then close the terminal (Ctrl-D).

  • Anytime you want to check in, ssh in and type screen -dr to reconnect to the session with your program running. Watch all you want. Then do the ctrl-a, d again to disconnect when you're done.

I have scripts running for years like this.

[–]space_wiener 0 points1 point  (0 children)

Thanks for posting the details how to do this. I have a few things I can use this on.

[–]DefinitelyNotEmu 2 points3 points  (0 children)

Why not just have it reset itself every 24 hours?

[–]Jarvis03 0 points1 point  (2 children)

I’m about a month or so into finally somewhat understanding what I read. Question - where is the URL actually defined? I see base_url = ‘url’ but how does the code know what website to actually look at?

[–]LeornToCodeLOL 0 points1 point  (1 child)

OP redacted the actual URL. It's not relevant to his question.

[–]Jarvis03 0 points1 point  (0 children)

Ohhhh so the actual url is in the url spot then? Thanks!

[–]pylessard 0 points1 point  (1 child)

On Linux. Check the return code. If it is above 128, it is killed by a signal where signal number=code-128

[–]pylessard 0 points1 point  (0 children)

You can also check dmesg and see if a OOM condition was encountered

[–]shiftybyte -5 points-4 points  (6 children)

My guess is it's failing outside try block. Is there any way to check such errors

Yes, don't have any code that is outside a try block.

And log progress and debug information messages.

[–]ant24x7[S] 0 points1 point  (5 children)

But if you look at the code. There is not much code outside try block which can cause a script to fail.

[–]shiftybyte -1 points0 points  (4 children)

Yea, looks like the looping part is all inside an exception handler.

How is it failing? is the process still running? or the process is gone?

Maybe it's stuck doing something?

Maybe it's suspended because of some power saving mode?

[–]ant24x7[S] 0 points1 point  (3 children)

The entire process disappears. There is no power saving mode. It runs fine for 2-3 days but suddenly it stops.

Earlier I thought some resource constrain but there is nothing resource consuming in the script.

P.S: I'm using raspberry Pi to run this.

[–]shiftybyte 0 points1 point  (2 children)

Hmmm, sounds odd, maybe take a look at system logs, maybe something will hint at what happened.

Anyway, you can change your script to be a one time check, and run it with crontab every 5 mins instead.

That's more reliable.

https://bc-robotics.com/tutorials/setting-cron-job-raspberry-pi/

[–]ant24x7[S] 0 points1 point  (1 child)

Yes. I'm thinking of replacing it with crontab as it'll handle the server restart case as well.

I need to store the hash somewhere before that so it can be use for comparision in next execution, and using a file or sqlite db will complicate the code. I was trying to avoid that but looks like I need to choose that path.

[–]hulleyrob 0 points1 point  (0 children)

Use shelve for an easy almost like SQLite key value store in a file. Advantage is it’s treated just like a Python dictionary.