On Tue, Aug 23, 2016 at 11:08 PM, dimao <dima.olk...@cell-buddy.com> wrote: > My current code takes almost 99% CPU usage. Here is the main part of my code : > > > PORT = 33123 > HOST = '127.0.0.1' > > > import asyncio > import os > > @asyncio.coroutine > def tcp_echo_client(offset): > > def send(offset): > MSG = """{"ClientId":"%s", % (str(offset))"}""" > > print("> " + MSG) > writer.write((MSG).encode("utf-8")) > > > def recv(): > msgback = (yield from reader.readline()).decode("utf-8").rstrip() > print("< " + msgback) > return msgback > > reader, writer = yield from asyncio.open_connection(HOST, port=PORT) > > > print(reader) > print('Waiting 3 sec for response...') > > while True: > response = yield from asyncio.wait_for(reader.readline(), > timeout=5.0) > print(response) > send(offset) > > yield from asyncio.sleep(0.5) >
Can you post your actual code, please? I'm not sure that this code is runnable - at least, not with this indentation. And if I have to fix your indentation to try to figure out what's nested inside what, I can't help with your CPU usage problem. ChrisA -- https://mail.python.org/mailman/listinfo/python-list