1 # Copyright (c) 2010-2022. The SimGrid Team. All rights reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the license (GNU LGPL) which comes with this package.
6 """ This example shows how to suspend and resume an asynchronous communication.
9 from argparse import ArgumentParser
12 from simgrid import Actor, Comm, Engine, Mailbox, this_actor
15 def create_parser() -> ArgumentParser:
16 parser = ArgumentParser()
21 help='path to the platform description'
27 mailbox: Mailbox = Mailbox.by_name("receiver")
28 payload = "Sent message"
30 # Create a communication representing the ongoing communication and then
31 simulated_size_in_bytes = 13194230
32 comm: Comm = mailbox.put_init(payload, simulated_size_in_bytes)
33 this_actor.info(f"Suspend the communication before it starts (remaining: {comm.remaining:.0f} bytes)"
34 f" and wait a second.")
35 this_actor.sleep_for(1)
36 this_actor.info(f"Now, start the communication (remaining: {comm.remaining:.0f} bytes) and wait another second.")
38 this_actor.sleep_for(1)
39 this_actor.info(f"There is still {comm.remaining:.0f} bytes to transfer in this communication."
40 " Suspend it for one second.")
42 this_actor.info(f"Now there is {comm.remaining:.0f} bytes to transfer. Resume it and wait for its completion.")
45 this_actor.info(f"There is {comm.remaining:.0f} bytes to transfer after the communication completion.")
46 this_actor.info(f"Suspending a completed activity is a no-op.")
51 mailbox: Mailbox = Mailbox.by_name("receiver")
52 this_actor.info("Wait for the message.")
53 received: str = mailbox.get()
54 this_actor.info(f"I got '{received}'.")
58 settings = create_parser().parse_known_args()[0]
60 e.load_platform(settings.platform)
61 Actor.create("sender", e.host_by_name("Tremblay"), sender)
62 Actor.create("receiver", e.host_by_name("Jupiter"), receiver)
66 if __name__ == "__main__":