This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author seer
Recipients aeros, asvetlov, seer, yselivanov
Date 2021-07-21.13:46:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626875179.77.0.215331684735.issue44697@roundup.psfhosted.org>
In-reply-to
Content
I write some short example.

import resource
import asyncio


class B:
    def __init__(self, loop):
        self.loop = loop
        self.some_big_data = bytearray(1024 * 1024)  # 1Mb for memory bloating

    async def doStuff(self):
        if not await self.connect():
            return
        print('Stuff done')

    async def connect(self) -> bool:
        try:
            _, writer = await asyncio.open_connection('127.0.0.1', 12345, loop=self.loop)
            writer.close()
            return True
        except OSError as e:
            pass
        return False


class A:
    def __init__(self, loop):
        self.loop = loop

    async def doBStuff(self):
        b = B(self.loop)
        await b.doStuff()

    async def work(self):
        print('Working...')
        for _ in range(1000):
            await self.loop.create_task(self.doBStuff())
        print('Done.')
        print(
            'Memory usage {}kb'.format(
                resource.getrusage(
                    resource.RUSAGE_SELF).ru_maxrss))


async def amain(loop):
    a = A(loop)
    await a.work()


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(amain(loop))


100 cycles
"Memory usage 41980kb"

1000 cycles
"Memory usage 55412kb"

10000 cycles
"Memory usage 82880kb"

And so on...

Does anyone know workaround?
History
Date User Action Args
2021-07-21 13:46:19seersetrecipients: + seer, asvetlov, yselivanov, aeros
2021-07-21 13:46:19seersetmessageid: <1626875179.77.0.215331684735.issue44697@roundup.psfhosted.org>
2021-07-21 13:46:19seerlinkissue44697 messages
2021-07-21 13:46:19seercreate