Skip to content

Commit

Permalink
Add nest_asyncio to run threaded queries (#737)
Browse files Browse the repository at this point in the history
* Add nest_asyncio to run threaded queries

* Fix incorrect import

* Fix call to net_asyncio.apply()

* Remove unrequired call to nest_asyncio
  • Loading branch information
FlorianBracq committed Dec 9, 2023
1 parent 74eeb2e commit ca2104b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions msticpy/data/core/query_provider_connections_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
from itertools import tee
from typing import Any, Dict, List, Optional, Protocol, Tuple, Union

import nest_asyncio
import pandas as pd
from tqdm.auto import tqdm


from ..._version import VERSION
from ...common.exceptions import MsticpyDataQueryError
from ...common.utility.ipython import is_ipython
from ..drivers.driver_base import DriverBase, DriverProps
from .query_source import QuerySource

Expand Down Expand Up @@ -377,6 +380,8 @@ async def _exec_queries_threaded(
def _get_event_loop() -> asyncio.AbstractEventLoop:
"""Return the current event loop, or create a new one."""
try:
if is_ipython():
nest_asyncio.apply()
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
Expand Down

0 comments on commit ca2104b

Please sign in to comment.