title: Calling coroutines in asyncio.Protocol.data_received
body: <p>I am having a problem doing asynchronous stuff in the <code>asyncio.Protocol.data_received</code> callback of the new Python <strong>asyncio</strong> module.</p>
  
  <p>Consider the following server:</p>
  
  <pre><code>class MathServer(asyncio.Protocol):
  
     @asyncio.coroutine
     def slow_sqrt(self, x):
        yield from asyncio.sleep(1)
        return math.sqrt(x)
  
     def fast_sqrt(self, x):
        return math.sqrt(x)
  
     def connection_made(self, transport):
        self.transport = transport
  
     #@asyncio.coroutine
     def data_received(self, data):
        print('data received: {}'.format(data.decode()))
        x = json.loads(data.decode())
        #res = self.fast_sqrt(x)
        res = yield from self.slow_sqrt(x)
        self.transport.write(json.dumps(res).encode('utf8'))
        self.transport.close()
  </code></pre>
  
  <p>used with the following client:</p>
  
  <pre><code>class MathClient(asyncio.Protocol):
  
     def connection_made(self, transport):
        transport.write(json.dumps(2.).encode('utf8'))
  
     def data_received(self, data):
        print('data received: {}'.format(data.decode()))
  
     def connection_lost(self, exc):
        asyncio.get_event_loop().stop()
  </code></pre>
  
  <p>With <code>self.fast_sqrt</code> being called, everything works as expected.</p>
  
  <p>With <code>self.slow_sqrt</code>, it does not work.</p>
  
  <p>It also does not work with <code>self.fast_sqrt</code> and the <code>@asyncio.coroutine</code> decorator on <code>data_received</code>.</p>
  
  <p>I feel I am missing something fundamental here.</p>
  
  <p>Complete code is here:</p>
  
  <ul>
  <li><a href="https://github.com/oberstet/scratchbox/blob/master/python/asyncio/server.py" rel="noreferrer">Server</a></li>
  <li><a href="https://github.com/oberstet/scratchbox/blob/master/python/asyncio/client.py" rel="noreferrer">Client</a></li>
  </ul>
  
  <p>Tested with:</p>
  
  <ul>
  <li>Python 3.4.0b1 (Windows)</li>
  <li>Python 3.3.3 + asyncio-0.2.1 (FreeBSD)</li>
  </ul>
  
  <p>The issue is the same on both: with <code>slow_sqrt</code>, the client/server will just hang doing nothing.</p>