network programming and sockets method if any task exits (stopiteration)it is discarded if task merely yieldsit is just placed back onto the task queue so that it can run again this continues until there are either no more tasks or all tasks are blockedwaiting for more / events as an optionthe mainloop(function accepts count parameter that can be used to make it return after specified number of / polling operations this might be useful if the scheduler is to be integrated into another event loop perhaps the most subtle aspect of the scheduler is the handling of systemcall instances in the mainloop(method if task yields systemcall instancethe scheduler invokes its handle(methodpassing in the associated scheduler and task objects as parameters the purpose of system call is to carry out some kind of internal operation concerning tasks or the scheduler itself the readwait()writewait()and newtask(classes are examples of system calls that suspend task for / or create new task for examplereadwait(takes task and invokes the readwait(method on the scheduler the scheduler then takes the task and places it into an appropriate holding area againthere is critical decoupling of objects going on here tasks yield systemcall objects to request servicebut do not directly interact with the scheduler systemcall objectsin turncan perform operations on tasks and schedulers but are not tied to any specific scheduler or task implementation soin theoryyou could write completely different scheduler implementation (maybe using threadsthat could just be plugged into this whole framework and it would still work here is an example of simple network time server implemented using this / task scheduler it will illuminate many of the concepts described in the previous listfrom socket import socketaf_inetsock_stream def time_server(address)import time socket(af_inet,sock_streams bind(addresss listen( while trueyield readwait(sconn,addr accept(print("connection from %sstr(addr)yield writewait(connresp time ctime("\ \nconn send(resp encode('latin- ')conn close(sched scheduler(sched new(time_server(('', ))sched new(time_server(('', ))sched run(server on port server on port in this exampletwo different servers are running concurrently--each listening on different port number (use telnet to connect and testthe yield readwait(and yield writewait(statements cause the coroutine running each server to suspend until / is possible on the associated socket when these statements returnthe code immediately proceeds with an / operation such as accept(or send( lib fl ff