pfm,
@pfm@edolas.world avatar

I've got this little program and it doesn't work as I expect it to:

from asyncio import start_server, run
from email import message_from_bytes
from email.policy import SMTPUTF8

async def handle_client(reader, writer):
    data = b''
    async for line in reader:
        data += line

    msg = message_from_bytes(data, policy=SMTPUTF8)
    print(f'Received key for {msg}')

    writer.close()
    await writer.wait_closed()
    print('Finished handling')

async def main():
    server = await start_server(handle_client, 'localhost', 10822)
    async with server:
        await server.serve_forever()

if __name__ == '__main__':
    run(main())

Then I send it a message with the following command:

nc localhost 10822 < input.txt

But nc doesn't exit. I have to interrupt it (Ctrl+C) and then my little program receives an EOF and finishes processing input. I don't understand this behaviour.

Any hints?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • DreamBathrooms
  • InstantRegret
  • thenastyranch
  • magazineikmin
  • GTA5RPClips
  • rosin
  • osvaldo12
  • tacticalgear
  • Youngstown
  • slotface
  • khanakhh
  • kavyap
  • ngwrru68w68
  • modclub
  • Leos
  • everett
  • provamag3
  • cubers
  • cisconetworking
  • ethstaker
  • Durango
  • mdbf
  • anitta
  • megavids
  • normalnudes
  • tester
  • JUstTest
  • lostlight
  • All magazines