<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run(classes, args=None, msg_stream=sys.stdout, verbose=False, util=None, event_loop=None, post_init_callback=None, green_mode=None, raises=False):
 """ Provides a simple way to run a tango server. It handles exceptions by writting a message to the msg_stream. The `classes` parameter can be either a sequence of: * :class:`~tango.server.Device` or * a sequence of two elements :class:`~tango.DeviceClass`, :class:`~tango.DeviceImpl` or * a sequence of three elements :class:`~tango.DeviceClass`, :class:`~tango.DeviceImpl`, tango class name (str) or a dictionary where: * key is the tango class name * value is either: * a :class:`~tango.server.Device` class or * a sequence of two elements :class:`~tango.DeviceClass`, :class:`~tango.DeviceImpl` or * a sequence of three elements :class:`~tango.DeviceClass`, :class:`~tango.DeviceImpl`, tango class name (str) The optional `post_init_callback` can be a callable (without arguments) or a tuple where the first element is the callable, the second is a list of arguments (optional) and the third is a dictionary of keyword arguments (also optional). .. note:: the order of registration of tango classes defines the order tango uses to initialize the corresponding devices. if using a dictionary as argument for classes be aware that the order of registration becomes arbitrary. If you need a predefined order use a sequence or an OrderedDict. Example 1: registering and running a PowerSupply inheriting from :class:`~tango.server.Device`:: from tango.server import Device, DeviceMeta, run class PowerSupply(Device):
 pass run((PowerSupply,)) Example 2: registering and running a MyServer defined by tango classes `MyServerClass` and `MyServer`:: from tango import Device_4Impl, DeviceClass from tango.server import run class MyServer(Device_4Impl):
 pass class MyServerClass(DeviceClass):
 pass run({'MyServer': (MyServerClass, MyServer)}) Example 3: registering and running a MyServer defined by tango classes `MyServerClass` and `MyServer`:: from tango import Device_4Impl, DeviceClass from tango.server import Device, DeviceMeta, run class PowerSupply(Device):
 pass class MyServer(Device_4Impl):
 pass class MyServerClass(DeviceClass):
 pass run([PowerSupply, [MyServerClass, MyServer]]) # or: run({'MyServer': (MyServerClass, MyServer)}) :param classes: a sequence of :class:`~tango.server.Device` classes or a dictionary where keyword is the tango class name and value is a sequence of Tango Device Class python class, and Tango Device python class :type classes: sequence or dict :param args: list of command line arguments [default: None, meaning use sys.argv] :type args: list :param msg_stream: stream where to put messages [default: sys.stdout] :param util: PyTango Util object [default: None meaning create a Util instance] :type util: :class:`~tango.Util` :param event_loop: event_loop callable :type event_loop: callable :param post_init_callback: an optional callback that is executed between the calls Util.server_init and Util.server_run :type post_init_callback: callable or tuple (see description above) :param raises: Disable error handling and propagate exceptions from the server :type raises: bool :return: The Util singleton object :rtype: :class:`~tango.Util` .. versionadded:: 8.1.2 .. versionchanged:: 8.1.4 when classes argument is a sequence, the items can also be a sequence <TangoClass, TangoClassClass>[, tango class name] .. versionchanged:: 9.2.2 `raises` argument has been added """

    server_run = functools.partial(
        __server_run, classes,
        args=args, msg_stream=msg_stream,
        util=util, event_loop=event_loop,
        post_init_callback=post_init_callback,
        green_mode=green_mode)
    # Run the server without error handling
    if raises:
        return server_run()
    # Run the server with error handling
    write = msg_stream.write if msg_stream else lambda msg: None
    try:
        return server_run()
    except KeyboardInterrupt:
        write("Exiting: Keyboard interrupt\n")
    except DevFailed as df:
        write("Exiting: Server exited with tango.DevFailed:\n" +
              str(df) + "\n")
        if verbose:
            write(traceback.format_exc())
    except Exception as e:
        write("Exiting: Server exited with unforseen exception:\n" +
              str(e) + "\n")
        if verbose:
            write(traceback.format_exc())
    write("\nExited\n")