Esempio n. 1
0
  def test_threading(self):
    stream_lock = threading.Lock()
    iostream = StringIO()
    output_length = 1000
    def testfunc(lock, stream):
      with utils.locked(lock):
        for x in xrange(output_length):
          stream.write(unicode(x))

    first = utils.spawn_thread(testfunc, stream_lock, iostream)
    second = utils.spawn_thread(testfunc, stream_lock, iostream)
    first.join()
    second.join()
    test_output = u''.join(unicode(x) for x in
                            range(output_length) + range(output_length))
    self.assertEqual(test_output, iostream.getvalue())
Esempio n. 2
0
    def test_threading(self):
        stream_lock = threading.Lock()
        iostream = StringIO()
        output_length = 1000

        def testfunc(lock, stream):
            with utils.locked(lock):
                for x in xrange(output_length):
                    stream.write(unicode(x))

        first = utils.spawn_thread(testfunc, stream_lock, iostream)
        second = utils.spawn_thread(testfunc, stream_lock, iostream)
        first.join()
        second.join()
        test_output = u''.join(
            unicode(x) for x in range(output_length) + range(output_length))
        self.assertEqual(test_output, iostream.getvalue())
Esempio n. 3
0
  def __init__(self, registrar):
    super(Latitude, self).__init__(registrar)
    usage = """
            USAGE: %s [noreverse]
            Gets the latitude and longitude from the authenticated
            Google Latitude account and then performs a reverse
            geolookup on it to get the most accurate address
            information for that location. If 'noreverse' is provided
            as an argument or there is no address info for the location,
            the plain latitude and longitude are returned.
           """
    registrar.register_service("latitude", self.execute,
      usage=usage,
      namespace=__name__)
    registrar.register_service("location", self.execute,
      usage=usage,
      namespace=__name__)

    utils.spawn_thread(self.location_updater)