def reset(self):
        """Clear all contexts in the thread.  Destroy the context if and only
        if we are in the main thread.
        """
        # Pop all active context.
        while driver.pop_active_context() is not None:
            pass

        # If it is the main thread
        if threading.current_thread() == self._mainthread:
            self._destroy_all_contexts()
Clear all contexts in the thread.  Destroy the context if and only
        if we are in the main thread.
        
numba/cuda/cudadrv/devices.py