# How to shutdown a trio-infinite-loop like the echo client from tutorial

**URL:** <https://trio.discourse.group/t/how-to-shutdown-a-trio-infinite-loop-like-the-echo-client-from-tutorial/181>\
**Category:** Help and advice\
**Created:** [June 17, 2019, 2:26pm UTC](https://trio.discourse.group/t/how-to-shutdown-a-trio-infinite-loop-like-the-echo-client-from-tutorial/181 "2019-06-17T14:26:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cloudostrich](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/cloudostrich/32/119_2.png) [@cloudostrich](https://trio.discourse.group/u/cloudostrich)\
**Post date:** [June 17, 2019, 2:26pm UTC](https://trio.discourse.group/t/how-to-shutdown-a-trio-infinite-loop-like-the-echo-client-from-tutorial/181/1 "2019-06-17T14:26:39Z")

</div>

Is there a way to manually exit a trio infinite loop, like the echo client in the trio tutorial, [https://trio.readthedocs.io/en/latest/tutorial.html#an-echo-client](https://trio.readthedocs.io/en/latest/tutorial.html#an-echo-client) , other than using Ctrl-C or using timeouts?

My idea is to use call the echo client from another python script, and be able to close it arbitrarily. I was thinking of using a flag (maybe event?) as a switch to trigger the cancel\_scope.cancel() in the nursery. But I am not sure how to do it. Greatly appreciate any help, Thanks.

---

<div class="post-metadata">

**Author:** ![njs](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/njs/32/11_2.png) [@njs](https://trio.discourse.group/u/njs)\
**Post date:** [June 18, 2019, 2:02am UTC](https://trio.discourse.group/t/how-to-shutdown-a-trio-infinite-loop-like-the-echo-client-from-tutorial/181/2 "2019-06-18T02:02:06Z")

</div>

You don’t really need to set a flag and then have that flag trigger a call to `cancel_scope.cancel()` – you can cut out the middleman, and call `cancel_scope.cancel()` directly :-).

It looks like your SO question has gotten some more detailed responses too; I’ll cross-link so folks here can find it:

> <https://stackoverflow.com/questions/56632002/how-to-manually-exit-an-infinite-trio-loop-like-the-trios-tutorial-echo-client>
