def __init__(self, file, get_needle_positions, machine,<EOL>on_message_received=(), left_end_needle=None,<EOL>right_end_needle=None):
self._file = file<EOL>self._on_message_received = on_message_received<EOL>self._machine = machine<EOL>self._state = WaitingForStart(self)<EOL>self._controller = None<EOL>self._last_requested_line_number = <NUM_LIT:0><EOL>self._needle_positions_cache = NeedlePositionCache(<EOL>get_needle_positions, self._machine)<EOL>self._left_end_needle = (<EOL>machine.left_end_needle<EOL>if left_end_needle is None else left_end_needle)<EOL>self._right_end_needle = (<EOL>machine.right_end_needle<EOL>if right_end_needle is None else right_end_needle)<EOL>self._lock = RLock()<EOL>self._thread = None<EOL>self._number_of_threads_receiving_messages = <NUM_LIT:0><EOL>self._on_message = []<EOL>
Create a new Communication object.

        :param file: a file-like object with read and write methods for the
          communication with the Arduino. This could be a
          :class:`serial.Serial` or a :meth:`socket.socket.makefile`.
        :param get_needle_positions: a callable that takes an :class:`index
          <int>` and returns :obj:`None` or an iterable over needle positions.
        :param AYABInterface.machines.Machine machine: the machine to use for
          knitting
        :param list on_message_received: an iterable over callables that takes
          a received :class:`message
          <AYABInterface.communication.hardware_messages.Message>` whenever
          it comes in. Since :attr:`state` changes only take place when a
          message is received, this can be used as an state observer.
        :param left_end_needle: A needle number on the machine.
          Other needles that are on the left side of this needle are not used
          for knitting. Their needle positions are not be set.
        :param right_end_needle: A needle number on the machine.
          Other needles that are on the right side of this needle are not used
          for knitting. Their needle positions are not be set.