Basic Parallel Execution
Run multiple agents in parallel usingasyncio.gather:
How It Works
1
Create Multiple Browser Instances
Each browser uses a separate user data directory to avoid conflicts
2
Define Independent Tasks
Create agents with different tasks that can run concurrently
3
Run in Parallel
Use
asyncio.gather() to execute all agent tasks simultaneously4
Collect Results
Gather all results once tasks complete, with error handling
Experimental Feature: Parallel execution is still experimental. Agents might conflict with each other in some scenarios.
Parallel Data Collection
Collect data from multiple sources simultaneously:Parallel Form Submissions
Submit forms to multiple sites simultaneously:Parallel Research Tasks
Gather information from multiple sources concurrently:Error Handling in Parallel Execution
Handle errors gracefully when running tasks in parallel:Performance Considerations
Optimizing Parallel Execution
Best Practices
1
Separate User Data Directories
Give each browser instance its own user data directory to prevent conflicts
2
Use Headless Mode
Enable headless mode for better performance when running multiple browsers
3
Implement Error Handling
Use
return_exceptions=True in asyncio.gather() to prevent one failure from stopping all tasks4
Limit Concurrency
Use
asyncio.Semaphore to limit concurrent tasks based on system resources5
Clean Up Resources
Ensure browser instances are properly closed after task completion
Concurrency Limits
Related Examples
- Data Scraping - Extract data from multiple sites in parallel
- Research - Gather information from multiple sources
- Shopping - Compare prices across multiple stores