import time


def two_way_communication_with_args(start, end):
    """Both sends and receives values to & from the main thread.

    Accepts arguments, puts them on the worker object.
    Receives values from main thread with ``incoming = yield``
    Optionally returns a value at the end
    """

    # do computationally intensive work here
    i = start
    while i < end:
        i += 1
        time.sleep(0.1)
        # incoming receives values from the main thread
        # while yielding sends values back to the main thread
        incoming = yield i
        i = incoming if incoming is not None else i

    # do optional teardown here
    return "done"