# Signal Handling Code colliding?

**URL:** <https://trio.discourse.group/t/signal-handling-code-colliding/359>\
**Category:** Uncategorized\
**Created:** [December 20, 2020, 9:45pm UTC](https://trio.discourse.group/t/signal-handling-code-colliding/359 "2020-12-20T21:45:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilb](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/gilb/32/260_2.png) [@gilb](https://trio.discourse.group/u/gilb)\
**Post date:** [December 20, 2020, 9:45pm UTC](https://trio.discourse.group/t/signal-handling-code-colliding/359/1 "2020-12-20T21:45:45Z")

</div>

Hi!

I am new to Trio (and to async) and am trying to incorporate this library into my trading program, which uses Alpaca Trading API. When I am running this small test:

```auto
import trio
import trade_class as TC
from datetime import datetime
from os import path

async def my_sleep():
    sym = 'AAPL'
    barset = tc.api.get_barset(sym, '1Min', limit=50 * 6.5 * 7, end=datetime.now())[sym]
    return barset

async def child(i):
    print(f" child{i}: started! sleeping now...")
    await trio.sleep(5)
    print(f" child{i}: exiting!")

async def parent():
    print("parent: started!")
    async with trio.open_nursery() as nursery:
        for i in range(1, 3):
            print(f"parent: spawning child{i}...")
            nursery.start_soon(child, i)
        print("parent: waiting for children to finish...")
        # -- we exit the nursery block here --
    print("parent: all done!")

FULL_DATA_FOLDER = path.join(path.dirname(path.abspath( __file__ )), 'data')
key_filename = path.join(FULL_DATA_FOLDER, 'key1.txt')
tc = TC.Alpaca_Obj(key_filename)
trio.run(parent)

```

– I get the following error:

```auto
c:\users\gil\envs\utils\lib\site-packages\trio\_core\_wakeup_socketpair.py:70: RuntimeWarning: It looks like Trio's signal handling code might have collided with another library you're using. If you're running Trio in guest mode, then this might mean you should set host_uses_signal_set_wakeup_fd=True. Otherwise, file a bug on Trio and we'll help you figure out what's going on.

```

I think the Alpaca API uses async/websockets, but I don’t invoke these in my own code.

With thanks!  
Gil

---

<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:** [December 21, 2020, 12:29am UTC](https://trio.discourse.group/t/signal-handling-code-colliding/359/2 "2020-12-21T00:29:44Z")

</div>

That warning means that someone is overriding the Python interpreter’s normal handling for control-C / `KeyboardInterrupt`, before you `import trio`. Note that it’s only a warning, not an actual error – control-C handling might be wonky afterwards, but your program will still continue.

So I guess the question is who’s doing that and why :-). I would guess it was the Alpaca Trading API, but you’re importing that _after_ Trio, so that doesn’t quite make sense…

Do you have any custom Python configuration that might be messing with control-C handling? How are you executing your script – in a terminal, in an IDE, …?

---

<div class="post-metadata">

**Author:** ![gilb](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/gilb/32/260_2.png) [@gilb](https://trio.discourse.group/u/gilb)\
**Post date:** [December 21, 2020, 11:28am UTC](https://trio.discourse.group/t/signal-handling-code-colliding/359/3 "2020-12-21T11:28:02Z")

</div>

Thanks.

I am running this code with ipython from inside a neovim terminal, so that might be it.

Also, I tried do comment out the Alpaca import to see if the warning is gone – and it was gone, but then when I removed the comment to reuse again the Alpaca import – the warning did not appear again!

In sum, the following is weird:

1. Neovim / IPython issues?
2. As you note, the Alpaca import occurs _after_ the trio import, but still effects the warning.
3. there is some states issue here, because the warning does not return when I re-run with the Alpaca import back (to clarify: only if I exit ipython and re-enter, the warning appears).

Also: Alpaca is not written in async, so I am hitting a brick wall anyway with this. Is there an easy recipe for making the Alpaca (or any other REST API module) async (they are using requests)?

I know the above is basic, I am just staring this async trio journey!

Thanks again,  
Gil

---

<div class="post-metadata">

**Author:** ![gilb](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/gilb/32/260_2.png) [@gilb](https://trio.discourse.group/u/gilb)\
**Post date:** [December 21, 2020, 12:32pm UTC](https://trio.discourse.group/t/signal-handling-code-colliding/359/4 "2020-12-21T12:32:22Z")

</div>

Quick update:

The same error occurs when I run the code from the command line using python (and not ipython), so we can check off anything related to IDE in relation to this.

---

<div class="post-metadata">

**Author:** ![gilb](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/gilb/32/260_2.png) [@gilb](https://trio.discourse.group/u/gilb)\
**Post date:** [December 21, 2020, 12:48pm UTC](https://trio.discourse.group/t/signal-handling-code-colliding/359/5 "2020-12-21T12:48:07Z")

</div>

I think I found it. The culprit was an import from `ipdb`:

```auto
from ipdb import set_trace

```

Is this a familiar issue with trio?

Gil

---

<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:** [December 21, 2020, 8:11pm UTC](https://trio.discourse.group/t/signal-handling-code-colliding/359/6 "2020-12-21T20:11:18Z")

</div>

> [@gilb](#):
>
> I think I found it. The culprit was an import from `ipdb` :

Huh, interesting!

> [@gilb](#):
>
> Is this a familiar issue with trio?

No, this is the first we’ve heard of it. Lucky you :-).

What does `signal.getsignal(signal.SIGINT)` say, just before you do `import trio`?

---

<div class="post-metadata">

**Author:** ![gilb](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/gilb/32/260_2.png) [@gilb](https://trio.discourse.group/u/gilb)\
**Post date:** [December 22, 2020, 5:38pm UTC](https://trio.discourse.group/t/signal-handling-code-colliding/359/7 "2020-12-22T17:38:09Z")

</div>

I think this turned off the warning.
