Yield a MySQL cursor

def _get_cursor(self):
        '''
        Yield a MySQL cursor
        '''
        _options = self._get_options()
        conn = MySQLdb.connect(host=_options['host'],
                               user=_options['user'],
                               passwd=_options['pass'],
                               db=_options['db'], port=_options['port'],
                               ssl=_options['ssl'])
        cursor = conn.cursor()
        try:
            yield cursor
        except MySQLdb.DatabaseError as err:
            log.exception('Error in ext_pillar MySQL: %s', err.args)
        finally:
            conn.close()