627
627
def _http_start(self, started):
628
628
"""Server thread main entry point. """
631
server = self._get_httpd()
632
self._http_base_url = '%s://%s:%s/' % (self._url_protocol,
633
self.host, self.port)
635
# Whatever goes wrong, we save the exception for the main
636
# thread. Note that since we are running in a thread, no signal
637
# can be received, so we don't care about KeyboardInterrupt.
638
self._http_exception = sys.exc_info()
640
if server is not None:
641
# From now on, exceptions are taken care of by the
642
# SocketServer.BaseServer or the request handler.
643
server.serve(started)
644
if not started.isSet():
645
# Hmm, something went wrong, but we can release the caller anyway
629
server = self._get_httpd()
630
self._http_base_url = '%s://%s:%s/' % (self._url_protocol,
631
self.host, self.port)
632
server.serve(started)
648
634
def _get_remote_url(self, path):
649
635
path_parts = path.split(os.path.sep)
679
665
self._home_dir = os.getcwdu()
680
666
self._local_path_parts = self._home_dir.split(os.path.sep)
681
667
self._http_base_url = None
683
670
# Create the server thread
684
671
started = threading.Event()
685
self._http_thread = threading.Thread(target=self._http_start,
672
self._http_thread = test_server.ThreadWithException(
673
event=started, target=self._http_start, args=(started,))
687
674
self._http_thread.setDaemon(True)
688
self._http_exception = None
689
675
self._http_thread.start()
690
676
# Wait for the server thread to start (i.e release the lock)
692
self._http_thread.name = self._http_base_url
693
if 'threads' in tests.selftest_debug_flags:
694
print 'Thread started: %s' % (self._http_thread.name,)
697
if self._http_exception is not None:
698
# Something went wrong during server start
699
exc_class, exc_value, exc_tb = self._http_exception
700
raise exc_class, exc_value, exc_tb
678
if self._httpd is None:
679
if 'threads' in tests.selftest_debug_flags:
680
print 'Server %s:% start failed ' % (self.host, self.port)
682
self._http_thread.name = self._http_base_url
683
if 'threads' in tests.selftest_debug_flags:
684
print 'Thread started: %s' % (self._http_thread.name,)
686
# If an exception occured during the server start, it will get raised
687
self._http_thread.join(timeout=0)
703
689
def stop_server(self):
704
690
"""See bzrlib.transport.Server.tearDown."""
705
self._httpd.shutdown()
706
if 'threads' in tests.selftest_debug_flags:
707
print 'Try joining: %s' % (self._http_thread.name,)
708
self._httpd.join_thread(self._http_thread)
709
if 'threads' in tests.selftest_debug_flags:
710
print 'Thread joined: %s' % (self._http_thread.name,)
691
if self._httpd is not None:
692
# The server has been started successfully, shut it down now
693
self._httpd.shutdown()
694
if 'threads' in tests.selftest_debug_flags:
695
print 'Try joining: %s' % (self._http_thread.name,)
696
self._httpd.join_thread(self._http_thread)
697
if 'threads' in tests.selftest_debug_flags:
698
print 'Thread joined: %s' % (self._http_thread.name,)
712
700
def get_url(self):
713
701
"""See bzrlib.transport.Server.get_url."""