~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ftp.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-13 16:02:37 UTC
  • mfrom: (2413.3.2 ftp_ignore_ebadf)
  • Revision ID: pqm@pqm.ubuntu.com-20070413160237-0weampli2rrmzjht
(John Arbash Meinel) When shutting down the test FtpServer, trap EBADF

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import os
32
32
import urllib
33
33
import urlparse
 
34
import select
34
35
import stat
35
36
import threading
36
37
import time
569
570
        self._port = self._ftp_server.getsockname()[1]
570
571
        # Don't let it loop forever, or handle an infinite number of requests.
571
572
        # In this case it will run for 100s, or 1000 requests
572
 
        self._async_thread = threading.Thread(target=asyncore.loop,
 
573
        self._async_thread = threading.Thread(
 
574
                target=FtpServer._asyncore_loop_ignore_EBADF,
573
575
                kwargs={'timeout':0.1, 'count':1000})
574
576
        self._async_thread.setDaemon(True)
575
577
        self._async_thread.start()
581
583
        asyncore.close_all()
582
584
        self._async_thread.join()
583
585
 
 
586
    @staticmethod
 
587
    def _asyncore_loop_ignore_EBADF(*args, **kwargs):
 
588
        """Ignore EBADF during server shutdown.
 
589
 
 
590
        We close the socket to get the server to shutdown, but this causes
 
591
        select.select() to raise EBADF.
 
592
        """
 
593
        try:
 
594
            asyncore.loop(*args, **kwargs)
 
595
        except select.error, e:
 
596
            if e.args[0] != errno.EBADF:
 
597
                raise
 
598
 
584
599
 
585
600
_ftp_channel = None
586
601
_ftp_server = None