Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Error w/ Suggested Usage #621

Open
ek8terina opened this issue May 5, 2022 · 2 comments
Open

Runtime Error w/ Suggested Usage #621

ek8terina opened this issue May 5, 2022 · 2 comments

Comments

@ek8terina
Copy link

ek8terina commented May 5, 2022

After doing pip install, I get a runtime issue from the suggested set up code with the following message:

RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom

Everything works just fine using the name = main wrapper with the suggested code:

import undetected_chromedriver as uc
if __name__ == '__main__':
      driver = uc.Chrome()
      driver.get('https://nowsecure.nl')

Without the if statement the runtime error is thrown! A little bit out of practice with the python multiprocessing library, but kind of confused because I thought this was a multiprocessing issue for Windows and I'm on macOS, but it works now so all's well that ends well, I guess.

If anyone else gets this error, hopefully the if main wrapper fixes it for you :)

MACHINE INFO:
System: macOS 12.1
Chrome: 100.0.4896.127
Python: 3.9.6
undetected-chromedriver: 3.1.5.post4

@Andrej-VB
Copy link

This has already been covered (multiple times) in previous issues.
#384, #519, #570.

As far as I understand, it's also possible to leave out the main wrapper by using the use_subprocess=True under uc.Chrome() options, but security-wise this is the better approach.

@sebdelsol
Copy link
Contributor

sebdelsol commented May 5, 2022

In order to create a detached Chrome browser process, undetected-chromedriver use multiprocessing.Process() here which actually spawns a process : in this case Python actually needs to create a new interpreter instance and re-import the code.

That's why you need to wrap your code with an if-clause to protect the code from executing multiple times.
Please check this answer and try it on your own why that's obviously needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants