You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using this awesome library for web scraping but when running browsers in parallel I get random crashes.
So this might be because the library is not thread-safe. In the following example I create two different instances of Chrome with playwhright.Run. Is this save to do?
package main
import (
"sync""github.com/crawler/internal/crawl"
)
funcmain() {
wg:= sync.WaitGroup{}
wg.Add(1)
gofunc() {
deferwg.Done()
// creates a new instances with playwhright.Runb1, err:=crawl.LauchBrowser(crawl.LaunchOptions{
Headless: false,
})
iferr!=nil {
panic("failed to launch browser"+err.Error())
}
fori:=0; i<10; i++ {
p, err:=crawl.NewPage(b1)
iferr!=nil {
panic("failed to create new page"+err.Error())
}
_, err=crawl.ScrapeHomePage(p, "https://google.com")
iferr!=nil {
panic("failed to scrape home page"+err.Error())
}
err=p.Context().Close()
iferr!=nil {
panic("failed to close context"+err.Error())
}
}
}()
wg.Add(1)
gofunc() {
b2, err:=crawl.LauchBrowser(crawl.LaunchOptions{
Headless: false,
})
iferr!=nil {
panic("failed to launch browser"+err.Error())
}
deferwg.Done()
fori:=0; i<10; i++ {
p, err:=crawl.NewPage(b2)
iferr!=nil {
panic("failed to create new page"+err.Error())
}
_, err=crawl.ScrapeHomePage(p, "https://example.com")
iferr!=nil {
panic("failed to scrape home page"+err.Error())
}
err=p.Context().Close()
iferr!=nil {
panic("failed to close context"+err.Error())
}
}
}()
wg.Wait()
}
The text was updated successfully, but these errors were encountered:
It can be considered safe for your use case. BrowserContext is isolated from each other, which is equivalent to opening multiple browser windows and each has its own temporary data directory and profile.
You need to be careful to avoid deadlocks like #481 and #391 .
I'm using this awesome library for web scraping but when running browsers in parallel I get random crashes.
So this might be because the library is not thread-safe. In the following example I create two different instances of Chrome with
playwhright.Run
. Is this save to do?The text was updated successfully, but these errors were encountered: