'Returns the current thread\'s `IOLoop`.
If an `IOLoop` is currently running or has been marked as
current by `make_current`, returns that instance.  If there is
no current `IOLoop` and ``instance`` is true, creates one.
.. versionchanged:: 4.1
Added ``instance`` argument to control the fallback to
`IOLoop.instance()`.
.. versionchanged:: 5.0
The ``instance`` argument now controls whether an `IOLoop`
is created automatically when there is none, instead of
whether we fall back to `IOLoop.instance()` (which is now
an alias for this method)'

@staticmethod
def current(instance=True):

    current = getattr(IOLoop._current, 'instance', None)
    if ((current is None) and instance):
        current = None
        if (asyncio is not None):
            from tornado.platform.asyncio import AsyncIOLoop, AsyncIOMainLoop
            if (IOLoop.configured_class() is AsyncIOLoop):
                current = AsyncIOMainLoop()
        if (current is None):
            current = IOLoop()
        if (IOLoop._current.instance is not current):
            raise RuntimeError('new    IOLoop    did    not    become    current')
    return current
