diff --git a/requirements.txt b/requirements.txt index eefa8a7..a76f020 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,25 +1,25 @@ -aiohttp>=3.8.0 -pyyaml>=6.0 -python-dotenv>=0.20.0 -requests>=2.27.0 -pillow>=9.0.0 -numpy>=1.24.0 -tqdm>=4.64.0 -transformers>=4.51.0 -torch>=2.0 -openai -accelerate>=0.28.0 -sentencepiece -safetensors -qwen-omni-utils -#playsound #install this if you have issues playingh the audio -#simpleaudio -pydub -google-genai -opencv-python -tiktoken -blobfile -huggingface_hub -#https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_main/bitsandbytes-1.33.7.preview-py3-none-win_amd64.whl if you using local transformer provider get bitsandbytes for windows -#https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_main/bitsandbytes-1.33.7.preview-py3-none-manylinux_2_24_x86_64.whl if you using local transformer provider get bitsandbytes for linux -#autoawq #install this if you using local transformer provider AWQ models +aiohttp>=3.8.0 +pyyaml>=6.0 +python-dotenv>=0.20.0 +requests>=2.27.0 +pillow>=9.0.0 +numpy>=1.24.0 +tqdm>=4.64.0 +transformers>=4.51.0 +torch>=2.0 +openai +accelerate>=0.28.0 +sentencepiece +safetensors +qwen-omni-utils +#playsound #install this if you have issues playingh the audio +#simpleaudio +pydub +google-genai +opencv-python +tiktoken +blobfile +huggingface_hub +#https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_main/bitsandbytes-1.33.7.preview-py3-none-win_amd64.whl if you using local transformer provider get bitsandbytes for windows +#https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_main/bitsandbytes-1.33.7.preview-py3-none-manylinux_2_24_x86_64.whl if you using local transformer provider get bitsandbytes for linux +#autoawq #install this if you using local transformer provider AWQ models diff --git a/send_request.py b/send_request.py index 81276d9..da12519 100644 --- a/send_request.py +++ b/send_request.py @@ -57,19 +57,41 @@ def run_async(coroutine): logger.error(f"run_async received non-coroutine object: {type(coroutine)}") return None - # Get or create event loop + # Check if there's already a running event loop try: - loop = asyncio.get_event_loop() - except RuntimeError: - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) + loop = asyncio.get_running_loop() + # If we get here, there's already a running loop + # We need to use asyncio.create_task() or run in a thread pool + import concurrent.futures + import threading - # Run the coroutine with proper error handling - try: - return loop.run_until_complete(coroutine) - except Exception as e: - logger.error(f"Error in run_async while executing coroutine: {str(e)}", exc_info=True) - return None + # Create a new event loop in a separate thread + def run_in_thread(): + new_loop = asyncio.new_event_loop() + asyncio.set_event_loop(new_loop) + try: + return new_loop.run_until_complete(coroutine) + finally: + new_loop.close() + + with concurrent.futures.ThreadPoolExecutor() as executor: + future = executor.submit(run_in_thread) + return future.result() + + except RuntimeError: + # No running event loop, create a new one + try: + loop = asyncio.get_event_loop() + except RuntimeError: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + + # Run the coroutine with proper error handling + try: + return loop.run_until_complete(coroutine) + except Exception as e: + logger.error(f"Error in run_async while executing coroutine: {str(e)}", exc_info=True) + return None except Exception as e: logger.error(f"Unexpected error in run_async: {str(e)}", exc_info=True)