'''
https://docs.python.org/ja/3.6/library/asyncio-eventloop.html#display-the-current-date-with-call-later
'''
import asyncio
import datetime
import logging

logging.basicConfig(level=logging.DEBUG)

def display_date(end_time, loop):
    print(datetime.datetime.now())
    if (loop.time() + 1.0) < end_time:
        loop.call_later(1, display_date, end_time, loop)
    else:
        loop.stop()

loop = asyncio.get_event_loop()

# Schedule the first call to display_date()
end_time = loop.time() + 5.0
loop.call_soon(display_date, end_time, loop)

# Blocking call interrupted by loop.stop()
loop.run_forever()
loop.close()
