how to process 2 pages in diffrent threads?
See original GitHub issuei want to open 2 pages and create 2 thread,thread 1 process page1,and thread 2 process page 2. i try this code
def run1(context):
page = context.new_page()
page.goto('https://page1')
page.wait_for_timeout(5000)
page.close()
def run2(context):
page = context.new_page()
page.goto('https://page2')
page.wait_for_timeout(1000)
page.close()
def main():
with sync_playwright() as playwright:
browser = playwright.chromium.launch(headless=False)
context = browser.new_context()
t=Thread(target=run1,args=(context,))
t1=Thread(target=run2,args=(context,))
t.start()
t1.start()
t.join()
t1.join()
context.close()
browser.close()
but first open page 1 and 5 seconds later ,it opens page 2. it oepens the pages one by one how can i process multi page in diffrent thread at same time
Issue Analytics
- State:
- Created 2 years ago
- Comments:28 (15 by maintainers)
Top Results From Across the Web
What resources are shared between threads? - Stack Overflow
The process model is based on two independent concepts: resource grouping and execution. Sometimes it is useful to separate them; this is where ......
Read more >How web browsers use Processes and Threads
If two processes need to talk, they can do so by using Inter Process Communication (IPC). Many applications are designed to work this...
Read more >Threads
Memory map with two threads. A process may be multithreaded, where the same program contains multiple concurrent threads of execution.
Read more >Threads vs. Processes: A Look At How They Work Within Your ...
In some cases, you'll see a process marked as “Not Responding.” Try quitting that process and see if your system runs better. If...
Read more >Reactive Multi-Threading with RxJava - Pitfalls and Solutions
... the coordinator thread loads pages of 3 messages at a time and forwards them to a thread pool of 2 worker threads...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Playwright isn’t thread safe so you need to start playwright separately for each thread or you can use
asyncio
can you show how to do it correctly with asyncio? and does firefox have any arguments like https://stackoverflow.com/a/58589026 to reduce the load on the processors? (I have many contexts running. 1 browser per process and many contexts per thread).
first I start the process -> start the asyncio loop in the process -> start the browser -> create about 5 threads, transfer the browser -> start about 5 contexts per thread. - This loads the server heavily (6 cores, 32 RAM), cores are loaded at 100% and then the browser is simply closed and “Target page, context or browser has been closed” ((