Why does my ftp script quit after couple of hours?

K

kk

Hi
This way the first time I did something with ftp stuff. I think that
generally it works but it stops working(quits or disappears) after
couple of hours of running.

This was a personal test-trial script for my own needs which was to
get my dynamic ip and broadcast to a client(I have a client script on
another computer). I sure could use something like DynDns for the same
purpose with easier management but I just wanted to give it a try to
see if i could even make it work .

Basically this script parses my ip from DynDns ip check page and
uploads it to the given ftp site. It works fine initially, it does
upload, it updates the Ip every hour but the problem is that after
couple of hours the Python console window disappears, I assume it
crashes. I know it does upload at least couple times(works for couple
hours). it might be something to do with ftp connection. I will
investigate that but I just wanted to see if I have any logic or some
kind of contextual problem in the script.


Here is the link to Pastie page
http://pastie.org/584152


Thanks
 
D

Diez B. Roggisch

kk said:
Hi
This way the first time I did something with ftp stuff. I think that
generally it works but it stops working(quits or disappears) after
couple of hours of running.

This was a personal test-trial script for my own needs which was to
get my dynamic ip and broadcast to a client(I have a client script on
another computer). I sure could use something like DynDns for the same
purpose with easier management but I just wanted to give it a try to
see if i could even make it work .

Basically this script parses my ip from DynDns ip check page and
uploads it to the given ftp site. It works fine initially, it does
upload, it updates the Ip every hour but the problem is that after
couple of hours the Python console window disappears, I assume it
crashes. I know it does upload at least couple times(works for couple
hours). it might be something to do with ftp connection. I will
investigate that but I just wanted to see if I have any logic or some
kind of contextual problem in the script.


Here is the link to Pastie page
http://pastie.org/584152


The code isn't very robust if anything happens retrieving the IP-website
- if for some reason the connection is broken, it won't catch any
ensuing IO-exception.

Also your way of extracing the IP is rather awkward, a simple re (often
not the right tool, but here certainl yes) would help:
>>> m = re.search(r"(([0-9]+\.){3}[0-9]+)", body)
>>> m.group(1) '85.177.92.101'
>>>


Diez
 
K

kk

Hi Diez

Thanks for your insight. The reason I chose the awkward method to
parse the ip digits is that I was not familiar with the regex module
and the Dyndns Ip page is pretty simple page. I guess it is time to
learn more about the Re module.

As far as robustness, I agree with your assestment. I guess my main
confusion with my result is that the console window just disappears. I
wonder if I can make the window stay even if it crashesor if there are
connection issues? I will createa seperate log file to see if I can
catch any issues in a log file.
 
F

Francesco Bochicchio

Hi
This way the first time I did something with ftp stuff. I think that
generally it works but it stops working(quits or disappears) after
couple of hours of running.

This was a personal test-trial script for my own needs which was to
get my dynamic ip and broadcast to a client(I have a client script on
another computer). I sure could use something like DynDns for the same
purpose with easier management but I just wanted to give it a try to
see if i could even make it work .

Basically this script parses my ip from DynDns ip check page and
uploads it to the given ftp site. It works fine initially, it does
upload, it updates the Ip every hour but the problem is that after
couple of hours the Python console window disappears, I assume it
crashes.  I know it does upload at least couple times(works for couple
hours). it might be something to do with ftp connection. I will
investigate that but I just wanted to see if I have any logic or some
kind of contextual problem in the script.

Here is the link to Pastie pagehttp://pastie.org/584152

Thanks

Try catching the exception inside the main loop, to prevent your
program to exit in case of failure:

if __name__=='__main__':
while True:
try:
writeExtFile(FILE_PATH,FILE_NAME)
uploadFile
(FTP_NAME,FTP_USER_NAME,FTP_PASSWD,FTP_FOLDER,FILE_NAME)
time.sleep(TIME_DELAY)
except:
err, det, tb = sys.exc_info()
print "ERROR =>", err, det # gives you a description of the
occurred failure
traceback.print_tb(tb) # this might be needed only for debug


Ciao
 
D

Diez B. Roggisch

kk said:
Hi Diez

Thanks for your insight. The reason I chose the awkward method to
parse the ip digits is that I was not familiar with the regex module
and the Dyndns Ip page is pretty simple page. I guess it is time to
learn more about the Re module.

As far as robustness, I agree with your assestment. I guess my main
confusion with my result is that the console window just disappears. I
wonder if I can make the window stay even if it crashesor if there are
connection issues? I will createa seperate log file to see if I can
catch any issues in a log file.

I'm not a Windows-user, but even there it should be possible to *first*
open the console, and then start the script in it.

That will keep it open & you can see the stacktrace.
Diez
 
K

kk

Awesome stuff, thank you so much for all the help. The
Pcomp.lang.python is the most helpful list I have encountered so
far :)
 
H

Hendrik van Rooyen

As far as robustness, I agree with your assestment. I guess my main
confusion with my result is that the console window just disappears. I
wonder if I can make the window stay even if it crashesor if there are
connection issues? I will createa seperate log file to see if I can
catch any issues in a log file.

try opening python with the -i flag - then the console window hangs around
after the script exits and you can examine variables and stuff.

- Hendrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top