r/stackoverflow • • Nov 28 '24

Java Help with Playwright 1.48.0 and Java 8: "Cannot find object to call adopt" Exception in Multithreaded Web Scraping

3 Upvotes

Hi everyone,
I am working on a web scraping project using Playwright 1.48.0 with Java 8. Here's the approach I am taking, followed by the issue I'm encountering:

My Approach:

  1. Browser Creation: For each top-level URL, I am creating a new Playwright browser instance.

  2. Multithreading for Sub-URLs: After creating the browser instance, I pass it to 20 threads. Each thread is responsible for crawling and scraping a subset of sub-URLs.

  3. Context and Page Management per Thread:

    • In each thread:

      • I create a new browser context using the shared browser instance.

      • Load a page in the new context and scrape its content.

      • Close the page and context once the scraping for that thread is done.

  4. Resource Cleanup: After all threads finish their work, I:

    • Close the browser instance.

    • Shut down Playwright.

The Issue:

Despite this structured approach, I often run into the following exception:
com.microsoft.playwright.PlaywrightException: Cannot find object to call __adopt__.

This exception seems to be related to how Playwright manages its internal objects and threading, but I can't pinpoint what's going wrong. The error is intermittent, which makes debugging even harder.

Observations and Hypotheses:

  • Shared Browser Instance Across Threads: Since all threads share the same browser instance, could this cause race conditions or resource contention issues?

  • Context Lifecycle Management: Each thread creates and destroys its own context. Could there be some delay or mismanagement in how contexts are being disposed of?

  • Java Thread-Safety Concerns: I'm using Java 8 with basic thread management. Could this issue be due to improper synchronization?

Key Questions:

  1. Thread-Safety: Is sharing a single browser instance across multiple threads a bad practice in Playwright? Would creating a browser per thread be more reliable, albeit resource-intensive?

  2. Proper Cleanup: What is the correct way to manage contexts and pages in a multithreaded Playwright application? Are there any best practices or patterns for this?

  3. Alternative Patterns: Should I consider using an ExecutorService or another thread management approach to ensure smoother handling of threads and resources?

Additional Details:

  • Java Version: Java 8

  • Playwright Version: 1.48.0

  • Error Frequency: Intermittent, but occurs more frequently under high thread loads or when scraping many URLs.

Any help or insights into what might be causing this issue would be greatly appreciated! If you’ve faced similar problems or have best practices for using Playwright with multithreading, I’d love to hear about it.

p.s., I have to stick with java 8 for now, and it has to be multi threaded.

Thanks in advance!


r/stackoverflow • • Nov 22 '24

Other code Stack Overflow - Very Flawed

3 Upvotes

I know i'm getting downvoted but at this point i've gotten used to it from SO. Stack overflow (I might refer to it as SO some times) has a few flaws and when I mean a few, I mean a lot, i'll just explain a couple.

Here on stack overflow, it's very easy to make a closed question. Take this situation: --- START OF SITUATION --

You are a beginner in programming, you ask a SO question for something, for this, let's say that you can't find a solution online or by youself and have read the guidelines and seen the typical stuff. You create a post only for it to get downvoted and flagged as a duplicate. The comments say it's not clear, you ask why it's not clear, you get an answer that doesn't even answer you asking why it's not clear and when you go and try to ask another question. You find out you are post banned for 6 months.

--- END OF SITUATION ---

That would be real disencourging to a beginner compared to something you would get through Reddit, Discord or <insert lots of other platforms here>. At that point it feels like only people who post perfect questions get to go farther. This is somewhat me, the difference is I bypassed that disencourgement but now I have about 3 or 4 banned accounts on SO and do not want to post questions on SO anymore with fear that account will get banned.

That's the first issue. The second one kinda threatens internet preservation. Start from the scenario of the previous situation. The closed question gets a comment answer because they can't post an offical answer on a closed question. Later the question is hidden, search engines might have indexed it and now it's 404 because of auto hiding and I've geninuely came across a 404 SO question removed that has been indexed by search engines. Now that question is now link rot. Thats the second issue.

These are both issues with Stack Overflow. I know this post won't fix anything but i'm just trying to get people to somewhat understand this is a ploblem with SO.

For the people blaming AI chatbots as the main issue SO is dying, the points in this post have also fueled going to AI chatbots.

Stack Overflow: https://stackoverflow.com/users/22126820/ltecher


r/stackoverflow • • Nov 13 '24

Question Stack Overflawed

3 Upvotes

I'm probably gonna get downvoted but I don't care. I wanna know if there are others who experienced the same.

I was making a program which had an issue. I already searched and saw many solutions online but it didn't work in my situation. So I asked a question in Stack Overflow.

They flagged it as duplicate and closed it. I thought, fair enough I saw that post as well. I edited my question stating that I already applied that solution as seen in the code and it didn't work. Someone else tried and said they can't replicate it but still kept the question closed.

I don't understand why it should still be closed when it's not resolved and it's not a duplicate. Sure it can't be replicated by that one person who commented but that doesn't mean it can't be replicated by others. Why not let it stay open so others can try?

Eventually, I solved it and added the solution as an edit just in case others might find the same issue.


r/stackoverflow • • Oct 29 '24

Question Unable to post a question, getting this error (IP censored, is dynamic IP)

Post image
3 Upvotes

r/stackoverflow • • Sep 27 '24

Python Help required

3 Upvotes

I am looking for ways to extract all the images in a PDF(especially scholarly articles/ academic papers/ research papers.). I have tried various libraries, but couldn't find a solution. Help is appreciated.


r/stackoverflow • • Sep 21 '24

Python Help with Matplotlib

Thumbnail reddit.com
3 Upvotes

r/stackoverflow • • Sep 02 '24

Python Running Nuitka in Python Code

3 Upvotes

What I'm trying to do in my Python application is have it so users could insert a Python script and have it compile to an EXE using Nuitka. Don't ask. However, I notice that this application can not work in all computers as the user will most likely not have it installed. Any way I could run Nuitka through importing or somehow have the Nuitka BAT file and module code in my source code?


r/stackoverflow • • Aug 07 '24

Let's Learn It!: Video 2 of Akka.Restaurant

3 Upvotes

Hail and well met! I'm doing another stream this Thursday (8/8) starting at 7pm CST. I'll be walking through Akka .Net again with the Akka.Restaurant project. We'll need to finish the overall walkthrough and do some cleanup.

Youtube: https://youtube.com/live/s2F5XBAuQm4?feature=share
Twitch: https://www.twitch.tv/sir_codesalot/schedule?seriesID=2af7f593-6ebb-45d5-a114-d2c271911a8d

Repository: https://github.com/briansain/Akka.Restaurant


r/stackoverflow • • Apr 20 '20

Initializing a variable..

3 Upvotes

I'm new to coding and I was wondering why you can do int x; x =5; print it then x=6; print it. But not int x=5; print it then int x =6; and print it.


r/stackoverflow • • Feb 18 '20

Why so many threads are being closed, but questions like "How to exit VIM" are still alive?

3 Upvotes

I tend to avoid stupid questions, I do research before I ask, yet there comes people that votes for closing the thread without giving reasons.

Example:

https://stackoverflow.com/questions/60280707/how-to-solve-race-condition-for-refresh-api-token-during-multiple-async-requests/60281000#60281000

I wish I could know what drives people to vote for closing


r/stackoverflow • • Jan 15 '20

Why was this post closed?

Post image
3 Upvotes

r/stackoverflow • • Jan 07 '20

Update: an agreement with Monica Cellio

Thumbnail
meta.stackexchange.com
3 Upvotes

r/stackoverflow • • Jan 04 '20

My questions keep being downvoted and voted to be closed for ridiculous reasons within minutes.

Thumbnail
stackoverflow.com
3 Upvotes

r/stackoverflow • • Dec 03 '19

The most copied StackOverflow snippet of all time is flawed!

Thumbnail programming.guide
3 Upvotes

r/stackoverflow • • Sep 29 '19

How can you upload to Put.re using JavaScript?

3 Upvotes

I am making an app and wanted to add a client-side uploader. I found a couple of services, including:

file.io

catbox

Uguu

put.re (probably the one I want to use)

They all support curl as seen from the documentation but as I said I want a preferably JavaScript solution for the client (I am kinda a newbie in JS), and if that is not possible maybe a PHP one? Thanks in advance, Filip


r/stackoverflow • • Jun 06 '19

Alternatives to Stack Overflow?

3 Upvotes

I ask questions in SO about once every couple months. The last 6 have been viewed a bunch but no comments, let alone an answer. I feel like I'm on a "don't help this guy" list.

Where else can I go to ask questions?


r/stackoverflow • • May 29 '19

Why are mods so incompetent and trigger happy on stackoverflow?

3 Upvotes

So here it goes... Basically, I have this question about ANDROID_ID and getting different values in apps (actually same value in ALL apps) versus in ADB: https://stackoverflow.com/questions/56359011/why-am-i-getting-different-values-for-android-id - now the mod or whatever he is Alex P. (user:1778421) has marked it as a duplicate of https://stackoverflow.com/questions/47551306/android-id-different-in-abd-and-in-code-on-api-26... now, if he'd be really competent, he'd know that starting from Android O (API 26) the way the ANDROID_ID is implemented has changed indeed like in the question he marked as already answered, BUT in my question, I've stated from the get-go that I'm using Android 5.1 (API 22) and ANDROID_ID is still system based and not different for each app so I shouldn't get different results... so how could my question be a duplicate and how can people benefit from stackoverflow when they have mods like this?

LE: after stating why I think know this isn't a duplicate when marked as possibly a duplicate, after still being marked as duplicate and stating again in bold why it isn't a duplicate, contacting stackoverflow directly with my problem, writing here, the question isn't marked as a duplicate anymore, but it's -1 now... I wonder who down-voted... crazy, huh? :)


r/stackoverflow • • May 27 '19

Anybody else having issue with the site today?

3 Upvotes

I can barely open anything. 90% of the time, I just got redirected to the error page.


r/stackoverflow • • Jan 05 '19

Can anyone please explain why and what happened to my post?

3 Upvotes

I was having trouble with a simple script in C# but I'm a noob so I couldn't figure exactly why my script wasn't working.

People started modifying the question (even if I'm not sure it was necessary, but it's ok).

About some weeks later the post has been flagged as "off-topic" (???) and then removed. I really don't undestand how. Even if the reason is somehow explained I can't figure what exactly is: the specific problem is in the description and the code for reproducing it is really short (even if the problem is actually in the include itself);

This is the question (I hope you can still see it).

Here is the post otherwise:


r/stackoverflow • • Oct 05 '18

What if someone tried to automate... the Stack Overflow Developer Survey?

3 Upvotes

As an experiment, I tried to automate the Stack Overflow Developer Survey, and I wanted to share my results with you all.

No, this is not about bots giving bogus answers to the questions in the survey. This is about gathering the required information about each user to automatically answer the questions.

Here's a link to my post.

Feedback welcome!


r/stackoverflow • • Sep 18 '18

Stackoverflow: Why can't we post comments on existing questions?Why do we need repo/karma for posting a comment?

3 Upvotes

I can find threads related to questions i am looking for. What if i want to ask further questions related to already asked question on that page/thread?


r/stackoverflow • • Jul 30 '18

Will I get my rep back when my account suspension ends?

3 Upvotes

My account was suspended because I called a mod out on blatant mod abuse. I'm not going to go into detail but I've spent the last 7-8 years building up a reputation here and I'd hate to lose all of that for one indiscretion - or one prick on the internet having some modicum of power on a single website having a bad attitude for that matter.

Will my rep return to its proper state when the suspension expires or am I totally screwed here?


r/stackoverflow • • Jun 29 '18

Why was my question downvoted so much?

3 Upvotes

My stackoverflow questions often get downvoted. Granted, some of them were not great questions, but I thought I'd finally asked a good one. However, it got severely downvoted as well. Even after reading the guide on how to ask a good question I still don't understand what could have made this a better post. Anybody have feedback?


r/stackoverflow • • May 20 '18

How to access your terminal window via the browser?

3 Upvotes

I want to access my ubuntu terminal using my browser i found a npm package web-terminal but it is kind off not complete.. I have seen jupyter notebook do it.. so is there a solution for it or a way to get that terminal thingy out of jupyter notebook.


r/stackoverflow • • May 18 '18

New people on stack Overflow

3 Upvotes

New people on stack Overflow are always shit on & never actually being told advice just being told that we are retarted & that we aren’t settling up our questions correctly. But I’m still fucking learning how to use the god damn website. I just want to know if everyone else is having these Problems or if I truly am just retarted