Note that there are some explanatory texts on larger screens.

plurals
  1. POThe thread hangs using FTP LIST with Python
    primarykey
    data
    text
    <p>I'm using ftplib for connecting and getting file list from FTP server. The problem I have is that the connection hangs from time to time and I don't know why. I'm running python script as a daemon, using threads. See what I mean:</p> <pre><code>def main(): signal.signal(signal.SIGINT, signal_handler) app.db = MySQLWrapper() try: app.opener = FTP_Opener() mainloop = MainLoop() while not app.terminate: # suspend main thread until the queue terminates # this lets to restart the queue automatically in case of unexpected shutdown mainloop.join(10) while (not app.terminate) and (not mainloop.isAlive()): time.sleep(script_timeout) print time.ctime(), "main: trying to restart the queue" try: mainloop = MainLoop() except Exception: time.sleep(60) finally: app.db.close() app.db = None app.opener = None mainloop = None try: os.unlink(PIDFILE) except: pass # give other threads time to terminate time.sleep(1) print time.ctime(), "main: main thread terminated" </code></pre> <p>MainLoop() has some functions for FTP connect, download specific files and disconnect from the server. </p> <p>Here's how I get the file's list:</p> <pre><code>file_list = app.opener.load_list() </code></pre> <p>And how FTP_Opener.load_list() function looks like:</p> <pre><code>def load_list(self): attempts = 0 while attempts&lt;=ftp_config.load_max_attempts: attempts += 1 filelist = [] try: self._connect() self._chdir() # retrieve file list to 'filelist' var self.FTP.retrlines('LIST', lambda s: filelist.append(s)) filelist = self._filter_filelist(self._parse_filelist(filelist)) return filelist except Exception: print sys.exc_info() self._disconnect() sleep(0.1) print time.ctime(), "FTP Opener: can't load file list" return [] </code></pre> <p>Why sometimes the FTP connection hangs and how can I monitor this? So if it happens I would like to terminate the thread somehow and start a new one.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload