Skip to content

Commit

Permalink
Patch nest_asyncio in notebooks only
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhulgakov authored and rlouf committed Jan 11, 2024
1 parent 1916392 commit 2767eff
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions outlines/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio
import builtins
import functools
import inspect
from typing import Callable, Optional

import nest_asyncio
import numpy as np
from numpy.lib.function_base import (
_calculate_shapes,
Expand All @@ -12,11 +12,17 @@
_update_dim_sizes,
)

# Allow nested loops, useful to run in notebooks
try:
nest_asyncio.apply()
except ValueError as e:
print("Could not apply nest_asyncio:", e)
# Allow nested loops for running in notebook. We don't enable it globally as it
# may interfere with other libraries that use asyncio.
if hasattr(builtins, "__IPYTHON__"):
try:
import nest_asyncio

nest_asyncio.apply()
except ImportError:
print(
"Couldn't patch nest_asyncio because it's not installed. Running in the notebook might be have issues"
)


class vectorize:
Expand Down

0 comments on commit 2767eff

Please sign in to comment.