Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:10:36+00:00 2026-06-13T02:10:36+00:00

I’m using ftplib for connecting and getting file list from FTP server. The problem

  • 0

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:

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"

MainLoop() has some functions for FTP connect, download specific files and disconnect from the server.

Here’s how I get the file’s list:

file_list = app.opener.load_list()

And how FTP_Opener.load_list() function looks like:

def load_list(self):
    attempts = 0
    while attempts<=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 []

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.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:10:37+00:00Added an answer on June 13, 2026 at 2:10 am

    If you are building for robustness, I would highly recommend that you look into using an event-driven method. One such which have FTP support is Twisted (API).

    The advantage is that you don’t block the thread while waiting for i/O and you can create simple timer functions to monitor your connections if you so prefer. It also scales a lot better. It is slightly more complicated to code using event-driven patterns, so if this is just a simple script it may or may not be worth the extra effort, but since you write that you are writing a daemon, it might be worth looking into.

    Here is an example of an FTP client: ftpclient.py

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.