#!/usr/bin/env python# -*- coding: utf-8 -*-# Created by vici on 09/03/2017# python tail -f | understand coroutinesimporttime# coroutine decoratordefcoroutine(func):defstart(*args,**kwargs):cr=func(*args,**kwargs)cr.next()returncrreturnstartdeffollow(thefile,target):print"start tail"thefile.seek(0,2)"""
seek(x, y ) the default is 0, means file beginning, 1 => current position
, 2=> end of file
"""whileTrue:line=thefile.readline()ifnotline:time.sleep(0.1)continueprint("[+] get 1 new line")target.send(line)@coroutinedefprinter():whileTrue:line=(yield)printline,if__name__=='__main__':importplatformprintplatform.python_version()f=open("1",'rb')printf.readline()printt=printer()follow(f,printt)