~robru/friends/refresh-fixup

« back to all changes in this revision

Viewing changes to friends/utils/base.py

  • Committer: Robert Bruce Park
  • Date: 2012-10-19 01:06:05 UTC
  • Revision ID: robert.park@canonical.com-20121019010605-66maduywe8icl564
Drop extraneous instance attribute from Authentication class.

This commit also does some minor cleanups, and introduces some new
debugging statements that may prove helpful in tracking down any
future hangs we discover.

Authentication._authenticating turned out to be redundant, I've
dropped it in favor of testing for the presence of self._reply
directly. Authentication.login sees that self._reply isn't populated
yet, so it blocks, and then the callback populates that value and
stops the lock, allowing login() to return that value.

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
class _OperationThread(threading.Thread):
106
106
    """Catch, log, and swallow all exceptions in the sub-thread."""
107
107
 
108
 
    def __init__(self, barrier, *args, **kws):
 
108
    def __init__(self, barrier, *args, identifier=None, **kws):
109
109
        # The barrier will only be provided when the system is under test.
110
110
        self._barrier = barrier
 
111
        self._id = identifier
111
112
        super().__init__(*args, **kws)
112
113
 
113
114
    # Always run these as daemon threads, so they don't block the main thread,
115
116
    daemon = True
116
117
 
117
118
    def run(self):
 
119
        log.debug('{} is starting in a new thread.'.format(self._id))
118
120
        try:
119
121
            super().run()
120
122
        except Exception:
124
126
        # the results, can then proceed.
125
127
        if self._barrier is not None:
126
128
            self._barrier.wait()
 
129
        log.debug('{} has completed, thread exiting.'.format(self._id))
127
130
 
128
131
 
129
132
class Base:
160
163
        # thread to assert the results of the sub-thread.
161
164
        barrier = (threading.Barrier(parties=2) if Base._SYNCHRONIZE else None)
162
165
        _OperationThread(barrier,
 
166
                         identifier='{}.{}'.format(self.__class__.__name__,
 
167
                                                   operation),
163
168
                         target=method, args=args, kwargs=kwargs).start()
164
169
        # When under synchronous testing, wait until the sub-thread completes
165
170
        # before returning.