diff --git a/aiida/manage/external/rmq.py b/aiida/manage/external/rmq.py index 8bfaf100f0..d7eabb5d6d 100644 --- a/aiida/manage/external/rmq.py +++ b/aiida/manage/external/rmq.py @@ -9,7 +9,9 @@ ########################################################################### # pylint: disable=cyclic-import """Components to communicate tasks to RabbitMQ.""" +import asyncio from collections.abc import Mapping +import gc import logging from kiwipy import communications, Future @@ -220,4 +222,10 @@ async def _continue(self, communicator, pid, nowait, tag=None): LOGGER.exception('failed to serialize the result for process<%d>', pid) raise + # before returning we ensure the garbage collection runs, to clear any memory used by the task + await asyncio.sleep(1) # allow other async tasks to complete first + del node + del result + gc.collect() + return serialized