curr - return json dumps(numsencode(@asyncio coroutine def sort_request(readerwriter)print("received connection"length yield from reader read( data yield from reader readexactlyint from_bytes(length'big')result yield from asyncio get_event_loop(run_in_executornonesort_in_processdataprint("sorted list"writer write(resultwriter close(print("connection closed"loop asyncio get_event_loop(loop set_default_executor(processpoolexecutor()server loop run_until_completeasyncio start_server(sort_request ' )print("sort service running"loop run_forever(server close(loop run_until_complete(server wait_closed()loop close(this is an example of good code implementing some really stupid ideas the whole idea of sort as service is pretty ridiculous using our own sorting algorithm instead of calling python' sorted is even worse the algorithm we used is called gnome sortor in some cases"stupid sortit is slow sort algorithm implemented in pure python we defined our own protocol instead of using one of the many perfectly suitable application protocols that exist in the wild even the idea of using multiprocessing for parallelism might be suspect herewe still end up passing all the data into and out of the subprocesses sometimesit' important to take step back from the program you are writing and ask yourself if you are trying to meet the right goals but let' look at some of the smart features of this design firstwe are passing bytes into and out of the subprocess this is lot smarter than decoding the json in the main process it means the (relatively expensivedecoding can happen on different cpu alsopickled json strings are generally smaller than pickled listsso less data is passing between processes