~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_server.py

  • Committer: Vincent Ladeuil
  • Date: 2010-06-30 15:19:36 UTC
  • mto: (5247.6.7 http-leaks)
  • mto: This revision was merged to the branch mainline in revision 5396.
  • Revision ID: v.ladeuil+lp@free.fr-20100630151936-bwh082le0i52p8ez
Fixed as per jam's review.

* bzrlib/tests/test_server.py:
* bzrlib/tests/test_http.py:
* bzrlib/tests/http_server.py:
* bzrlib/tests/ftp_server/pyftpdlib_based.py:
* bzrlib/tests/ftp_server/medusa_based.py:
Use sys.stderr.write() rather than print for thread dbugging trace.

* bzrlib/osutils.py:
(connect_socket): Remove the timeout parameter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
375
375
        self.serving.set()
376
376
        self.is_shut_down.clear()
377
377
        if 'threads' in tests.selftest_debug_flags:
378
 
            print 'Starting %r' % (self.server_address,)
 
378
            sys.stderr.write('Starting %r\n' % (self.server_address,))
379
379
        # We are listening and ready to accept connections
380
380
        started.set()
381
381
        while self.serving.isSet():
382
382
            if 'threads' in tests.selftest_debug_flags:
383
 
                print 'Accepting on %r' % (self.server_address,)
 
383
                sys.stderr.write('Accepting on %r\n' % (self.server_address,))
384
384
            # Really a connection but the python framework is generic and
385
385
            # call them requests
386
386
            self.handle_request()
387
387
        if 'threads' in tests.selftest_debug_flags:
388
 
            print 'Closing  %r' % (self.server_address,)
 
388
            sys.stderr.write('Closing  %r\n' % (self.server_address,))
389
389
        # Let's close the listening socket
390
390
        self.server_close()
391
391
        if 'threads' in tests.selftest_debug_flags:
392
 
            print 'Closed   %r' % (self.server_address,)
 
392
            sys.stderr.write('Closed   %r\n' % (self.server_address,))
393
393
        self.is_shut_down.set()
394
394
 
395
395
    def join_thread(self, thread, timeout=2):
461
461
                # Right, the socket is already down
462
462
                pass
463
463
            else:
464
 
                print 'exception in shutdown_client_socket: %r' % (e,)
 
464
                sys.stderr.write('exception in shutdown_client_socket: %r\n'
 
465
                                 % (e,))
465
466
                raise
466
467
 
467
468
 
506
507
 
507
508
    def process_request_thread(self, started, request, client_address):
508
509
        if 'threads' in tests.selftest_debug_flags:
509
 
            print 'Processing: %s' % (threading.currentThread().name,)
 
510
            sys.stderr.write('Processing: %s\n'
 
511
                             % (threading.currentThread().name,))
510
512
        started.set()
511
513
        SocketServer.ThreadingTCPServer.process_request_thread(
512
514
            self, request, client_address)
524
526
            args = (started, request, client_address))
525
527
        t.name = '%s -> %s' % (client_address, self.server_address)
526
528
        if 'threads' in tests.selftest_debug_flags:
527
 
            print 'Thread for: %s started' % (threading.currentThread().name,)
 
529
            sys.stderr.write('Thread for: %s started\n'
 
530
                             % (threading.currentThread().name,))
528
531
        client.append(t)
529
532
        self.clients.append(client)
530
533
        if self.daemon_threads:
540
543
            # shutdown.
541
544
            sock, addr, thread = client
542
545
            if 'threads' in tests.selftest_debug_flags:
543
 
                print 'Try    joining: %s' % (thread.name,)
 
546
                sys.stderr.write('Try    joining: %s\n' % (thread.name,))
544
547
            self.join_thread(thread)
545
548
 
546
549
    def server_bind(self):
666
669
        started.wait()
667
670
        if self._httpd is None:
668
671
            if 'threads' in tests.selftest_debug_flags:
669
 
                print 'Server %s:% start failed ' % (self.host, self.port)
 
672
                sys.stderr.write('Server %s:% start failed \n'
 
673
                                 % (self.host, self.port))
670
674
        else:
671
675
            self._http_thread.name = self._http_base_url
672
676
            if 'threads' in tests.selftest_debug_flags:
673
 
                print 'Thread started: %s' % (self._http_thread.name,)
 
677
                sys.stderr.write('Thread started: %s\n'
 
678
                                 % (self._http_thread.name,))
674
679
 
675
680
        # If an exception occured during the server start, it will get raised
676
681
        self._http_thread.join(timeout=0)
681
686
            # The server has been started successfully, shut it down now
682
687
            self._httpd.shutdown_server()
683
688
            if 'threads' in tests.selftest_debug_flags:
684
 
                print 'Try    joining: %s' % (self._http_thread.name,)
 
689
                sys.stderr.write('Try    joining: %s\n'
 
690
                                 % (self._http_thread.name,))
685
691
            self._httpd.join_thread(self._http_thread)
686
692
            if 'threads' in tests.selftest_debug_flags:
687
 
                print 'Thread  joined: %s' % (self._http_thread.name,)
 
693
                sys.stderr.write('Thread  joined: %s\n'
 
694
                                 % (self._http_thread.name,))
688
695
 
689
696
    def get_url(self):
690
697
        """See bzrlib.transport.Server.get_url."""