Repository: explodinggradients/ragas
Issue: Task pending attached to a different loop | RuntimeError
Root cause: Resource Mishandling


```python
class TestsetGeneratorFactory(TestsetGenerator):
    
    generator_llm: BaseRagasLLM
    critic_llm: BaseRagasLLM
    embeddings: BaseRagasEmbeddings
    docstore: DocumentStore
        
    def with_google(
        generator_llm: str = "chat-bison-32k",
        critic_llm: str = "gemini-1.0-pro-001",
        embeddings: str = "textembedding-gecko@003",
        docstore: t.Optional[DocumentStore] = None,
        run_config: t.Optional[RunConfig] = None,
        chunk_size: int = 1024,
    ) -> TestsetGenerator:
        generator_llm_model = LangchainLLMWrapper(ChatVertexAI(model=generator_llm))
        critic_llm_model = LangchainLLMWrapper(ChatVertexAI(model=critic_llm))
        embeddings_model = LangchainEmbeddingsWrapper(VertexAIEmbeddings(model_name="textembedding-gecko@001"))
        keyphrase_extractor = KeyphraseExtractor(llm=generator_llm_model)
        if docstore is None:
            from langchain.text_splitter import TokenTextSplitter

            splitter = TokenTextSplitter(chunk_size=chunk_size, chunk_overlap=0)
            docstore = InMemoryDocumentStore(
                splitter=splitter,
                embeddings=embeddings_model,
                extractor=keyphrase_extractor,
                run_config=run_config,
            )
            return TestsetGenerator(
                generator_llm=generator_llm_model,
                critic_llm=critic_llm_model,
                embeddings=embeddings_model,
                docstore=docstore,
            )
        else:
            return TestsetGenerator(
                generator_llm=generator_llm_model,
                critic_llm=critic_llm_model,
                embeddings=embeddings_model,
                docstore=docstore,
            )

generator = TestsetGeneratorFactory.with_google()

# Change resulting question type distribution
distributions = {
    simple: 1,
    multi_context: 0,
    reasoning: 0
}

# use generator.generate_with_llamaindex_docs if you use llama-index as document loader
testset = generator.generate_with_langchain_docs(documents, 
                                                 10, 
                                                 distributions,
                                                 is_async = True)
testset.to_pandas()
```

Tried running above code and ran into `RuntimeError`

```
Exception in thread Thread-107:
Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/ragas/executor.py", line 93, in run
    results = self.loop.run_until_complete(self._aresults())
  File "/opt/conda/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/ragas/executor.py", line 81, in _aresults
    raise e
  File "/home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/ragas/executor.py", line 76, in _aresults
    r = await future
  File "/opt/conda/lib/python3.10/asyncio/tasks.py", line 571, in _wait_for_one
    return f.result()  # May raise f.exception().
  File "/home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/ragas/executor.py", line 36, in sema_coro
    return await coro
  File "/home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/ragas/executor.py", line 109, in wrapped_callable_async
    return counter, await callable(*args, **kwargs)
  File "/home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/ragas/testset/extractor.py", line 49, in extract
    results = await self.llm.generate(prompt=prompt, is_async=is_async)
  File "/home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/ragas/llms/base.py", line 92, in generate
    return await agenerate_text_with_retry(
  File "/home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/tenacity/_asyncio.py", line 88, in async_wrapped
    return await fn(*args, **kwargs)
  File "/home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/tenacity/_asyncio.py", line 47, in __call__
...
    response = yield from self._call.__await__()
  File "/home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/grpc/aio/_call.py", line 299, in __await__
    response = yield from self._call_response
RuntimeError: Task <Task pending name='Task-2394' coro=<BaseChatModel._agenerate_with_cache() running at /home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py:617> cb=[gather.<locals>._done_callback() at /opt/conda/lib/python3.10/asyncio/tasks.py:720]> got Future <Task pending name='Task-2395' coro=<UnaryUnaryCall._invoke() running at /home/jupyter/gai-knowledge-assistant-1/projects/backend/.venv/lib/python3.10/site-packages/grpc/aio/_call.py:568>> attached to a different loop
```