# Path: concert/config.py
# AIODEBUG = 9
# 
# Path: concert/coroutines/base.py
# def background(coroutine):
#     """Same as :func:`.start`, just meant to be used as a decorator."""
#     @functools.wraps(coroutine)
#     def inner(*args, **kwargs):
#         return start(coroutine(*args, **kwargs))
# 
#     return inner
# 
# def run_in_loop(coroutine):
#     """Wrap *coroutine* into a `asyncio.Task`, run it in the current loop, block until it finishes
#     and return the result.  On KeyboardInterrupt, the task is cancelled.
#     """
#     loop = asyncio.get_event_loop()
#     task = asyncio.ensure_future(coroutine, loop=loop)
# 
#     try:
#         result = loop.run_until_complete(task)
#         return result
#     except KeyboardInterrupt:
#         # _coro instead of get_coro() for Python 3.7 compatibilityget_coro()
#         LOG.log(AIODEBUG, "KeyboardInterrupt in `%s', cancelling", task._coro.__qualname__)
#         task.cancel()
# 
# Path: concert/devices/base.py
# class Device(Parameterizable):
# 
#     """
#     A :class:`.Device` provides locked access to a real-world device.
# 
#     It implements the context protocol to provide locking::
# 
#         async with device:
#             # device is locked
#             await device.set_parameter(1 * q.m)
#             ...
# 
#         # device is unlocked again
#     """
# 
#     def __init__(self):
#         # We have to create the lock early on because it will be accessed in
#         # any add_parameter calls, especially those in the Parameterizable base
#         # class
#         self._lock = asyncio.Lock()
#         super(Device, self).__init__()
# 
#     async def __aenter__(self):
#         await self._lock.acquire()
# 
#         return self
# 
#     async def __aexit__(self, exc_type, exc, tb):
#         self._lock.release()
# 
#     @background
#     async def emergency_stop(self):
#         """Emergency stop."""
#         await self._emergency_stop()
# 
#     async def _emergency_stop(self):
#         """Emergency stop implementation."""
#         pass
# 
# Path: concert/quantities.py



import asyncio
import logging
import math
import os
import inspect
import subprocess
import prettytable
    import concert.coroutines.base as cbase
    import functools
    import threading
from concert.config import AIODEBUG
from concert.coroutines.base import background, run_in_loop
from concert.devices.base import Device
from concert.quantities import q
    from concert.devices.base import Device
        from pygments import highlight
        from pygments.lexers import PythonLexer
        from pygments.formatters import TerminalFormatter


def abort_awaiting(background=False, skip=None):
    """Abort task currently being awaited in the session. Return True if there is a task being
    awaited, otherwise False. This function does not touch tasks running in the background unless
    *background* is True, in which case it cancels all awaitables.
    """

    # Figure out if we are in a callback (ctrl-c or ctrl-k) or check_emergency_stop
    try:
        asyncio.get_running_loop()
    except RuntimeError:
        loop_running = False
    else:
        loop_running = True
    LOG.log(AIODEBUG, 'async code: %s', loop_running)

    def get_task_name(task):
        # _coro instead of get_coro() for Python 3.7 compatibility
        return task._coro.__qualname__

    def get_task_directory(task):
        # _coro instead of get_coro() for Python 3.7 compatibility
        return os.path.dirname(task._coro.cr_code.co_filename)

    if cbase._TLOOP:
        def thread_callback(event, task):
            event.set()

        tasks = asyncio.all_tasks(loop=cbase._TLOOP)

# Path: concert/config.py
# AIODEBUG = 9
# 
# Path: concert/coroutines/base.py
# def background(coroutine):
#     """Same as :func:`.start`, just meant to be used as a decorator."""
#     @functools.wraps(coroutine)
#     def inner(*args, **kwargs):
#         return start(coroutine(*args, **kwargs))
# 
#     return inner
# 
# def run_in_loop(coroutine):
#     """Wrap *coroutine* into a `asyncio.Task`, run it in the current loop, block until it finishes
#     and return the result.  On KeyboardInterrupt, the task is cancelled.
#     """
#     loop = asyncio.get_event_loop()
#     task = asyncio.ensure_future(coroutine, loop=loop)
# 
#     try:
#         result = loop.run_until_complete(task)
#         return result
#     except KeyboardInterrupt:
#         # _coro instead of get_coro() for Python 3.7 compatibilityget_coro()
#         LOG.log(AIODEBUG, "KeyboardInterrupt in `%s', cancelling", task._coro.__qualname__)
#         task.cancel()
# 
# Path: concert/devices/base.py
# class Device(Parameterizable):
# 
#     """
#     A :class:`.Device` provides locked access to a real-world device.
# 
#     It implements the context protocol to provide locking::
# 
#         async with device:
#             # device is locked
#             await device.set_parameter(1 * q.m)
#             ...
# 
#         # device is unlocked again
#     """
# 
#     def __init__(self):
#         # We have to create the lock early on because it will be accessed in
#         # any add_parameter calls, especially those in the Parameterizable base
#         # class
#         self._lock = asyncio.Lock()
#         super(Device, self).__init__()
# 
#     async def __aenter__(self):
#         await self._lock.acquire()
# 
#         return self
# 
#     async def __aexit__(self, exc_type, exc, tb):
#         self._lock.release()
# 
#     @background
#     async def emergency_stop(self):
#         """Emergency stop."""
#         await self._emergency_stop()
# 
#     async def _emergency_stop(self):
#         """Emergency stop implementation."""
#         pass
# 
# Path: concert/quantities.py



# Path: concert/session/utils.py
import asyncio
import logging
import math
import os
import inspect
import subprocess
import prettytable
    import concert.coroutines.base as cbase
    import functools
    import threading
from concert.config import AIODEBUG
from concert.coroutines.base import background, run_in_loop
from concert.devices.base import Device
from concert.quantities import q
    from concert.devices.base import Device
        from pygments import highlight
        from pygments.lexers import PythonLexer
        from pygments.formatters import TerminalFormatter



def abort_awaiting(background=False, skip=None):
    """Abort task currently being awaited in the session. Return True if there is a task being
    awaited, otherwise False. This function does not touch tasks running in the background unless
    *background* is True, in which case it cancels all awaitables.
    """

    # Figure out if we are in a callback (ctrl-c or ctrl-k) or check_emergency_stop
    try:
        asyncio.get_running_loop()
    except RuntimeError:
        loop_running = False
    else:
        loop_running = True
    LOG.log(AIODEBUG, 'async code: %s', loop_running)

    def get_task_name(task):
        # _coro instead of get_coro() for Python 3.7 compatibility
        return task._coro.__qualname__

    def get_task_directory(task):
        # _coro instead of get_coro() for Python 3.7 compatibility
        return os.path.dirname(task._coro.cr_code.co_filename)

    if cbase._TLOOP:
        def thread_callback(event, task):
            event.set()

        tasks = asyncio.all_tasks(loop=cbase._TLOOP)

        LOG.log(AIODEBUG, 'Running %d tasks in separate thread:%s', len(tasks),