In [1]:
import asyncio
import datetime

In [2]:
@asyncio.coroutine
def display_date():
    dt = datetime.datetime
    end_time = dt.now().timestamp() + 5.0
    while True:
        dt = datetime.datetime
        print(dt.now())
        if (dt.now().timestamp() + 1.0) >= end_time:
            break
        yield from asyncio.sleep(1)

In [3]:
loop = asyncio.get_event_loop()
loop.run_until_complete(display_date())
loop.close()


2016-07-20 22:14:15.839028
2016-07-20 22:14:16.843081
2016-07-20 22:14:17.847200
2016-07-20 22:14:18.850101
2016-07-20 22:14:19.850391
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-8f00903fc0ce> in <module>()
      1 loop = asyncio.get_event_loop()
      2 server = loop.run_until_complete(display_date())
----> 3 server.close()
      4 loop.close()

AttributeError: 'NoneType' object has no attribute 'close'

In [ ]: