crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] Unable to run flows in Google Colab

Open ziaukhan opened this issue 1 year ago • 1 comments

Description

I am unable to run flows in Google colab:

https://colab.research.google.com/drive/1RRsBLOh-3BgshTBJrSfdMChdV8SX0vFI?usp=sharing

Steps to Reproduce

Just run the notebook

Expected behavior

It should run the flow

Screenshots/Code snippets

I have tried all the different options to run flow

Operating System

Ubuntu 20.04

Python Version

3.12

crewAI Version

0.80

crewAI Tools Version

0.80

Virtual Environment

Poetry

Evidence

RuntimeError: asyncio.run() cannot be called from a running event loop

Possible Solution

all tried all the solution i know

Additional context

Cant find a single example of running flows in google colab

ziaukhan avatar Nov 24 '24 12:11 ziaukhan

Solution

The issue arises because Google Colab runs in an environment with an already active asyncio event loop. This prevents the direct use of asyncio.run() as it conflicts with the existing loop. To resolve this, you can use the nest_asyncio library, which allows nested asyncio loops by patching the existing event loop.

Here are the steps to fix the issue: 1. Install nest_asyncio in your Colab environment:

!pip install nest_asyncio

2.	Import and apply nest_asyncio at the beginning of your notebook or before running your flow:

import nest_asyncio nest_asyncio.apply()

3.	Continue with the rest of your code as usual. The nest_asyncio.apply() will allow you to run your flow within the Colab’s environment.

Updated Code Example

Install the required package

!pip install nest_asyncio

Import and apply nest_asyncio

import nest_asyncio nest_asyncio.apply()

Continue with your flow

Example

from crewai import Flow

async def example_flow(): print("Flow running")

Flow.run(example_flow())

Additional Notes • This issue is specific to environments like Google Colab where an event loop is pre-running. nest_asyncio is a well-established solution for such scenarios. • Ensure all dependencies, including crewai, are correctly installed in your Colab environment.

Let me know if this resolves your issue or if you encounter further challenges!

EnggQasim avatar Dec 03 '24 10:12 EnggQasim

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jan 02 '25 12:01 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Jan 07 '25 12:01 github-actions[bot]