# Alpaca-backtrader-api gives threading error on running sample code

**URL:** <https://forum.alpaca.markets/t/alpaca-backtrader-api-gives-threading-error-on-running-sample-code/528>\
**Category:** Alpaca Integration Applications\
**Created:** [December 13, 2019, 9:00pm UTC](https://forum.alpaca.markets/t/alpaca-backtrader-api-gives-threading-error-on-running-sample-code/528 "2019-12-13T21:00:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Chris\_Jones](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/chris_jones/32/74_2.png) [@Chris\_Jones](https://forum.alpaca.markets/u/Chris_Jones)\
**Post date:** [December 20, 2019, 4:24am UTC](https://forum.alpaca.markets/t/alpaca-backtrader-api-gives-threading-error-on-running-sample-code/528/2 "2019-12-20T04:24:17Z")

</div>

The error seems to point to this line in stream2.py:

> [@harsh\_upreti](#):
>
> File “/Users/harshupreti/Desktop/Trades/Alpaca/nightwatch/venv/lib/python3.7/site-packages/alpaca\_trade\_api/stream2.py”, line 27, in **init** self.loop = asyncio.get\_event\_loop()

IF you want to go comment out line 27 and replace it with(or add the lines):

```auto
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)

```

It will run.

Here is a great description of the problem:

> <https://stackoverflow.com/questions/46727787/runtimeerror-there-is-no-current-event-loop-in-thread-in-async-apscheduler>

---

_[View the full topic](https://forum.alpaca.markets/t/alpaca-backtrader-api-gives-threading-error-on-running-sample-code/528)._
