elceef / dnstwist

Domain name permutation engine for detecting homograph phishing attacks, typo squatting, and brand impersonation
https://dnstwist.it
Apache License 2.0
4.76k stars 761 forks source link

ValueError: signal only works in main thread of the main interpreter #153

Closed dodancs closed 1 year ago

dodancs commented 2 years ago

Hey, I have a problem. It is exactly what is described in the title.

I get this error message when trying to use dnstwist from a thread in python. Do you have any suggestions on how to fix this?

Thanks!

elceef commented 2 years ago

You provided very little information, so I'm guessing that this exception is raised when dnstwist tries to set its custom handler for signal SIGINT and SIGTERM.

ccwillem commented 2 years ago

Hello, I'm having the same problem.

I'm running the "API" call 'data = dnstwist.run(domain='domain.name', registered=True, format='null')' from inside the main function of another python script and I get the following errors:

Exception: ValueError: signal only works in main thread of the main interpreter
File "*********/.venv/lib/python3.9/site-packages/dnstwist.py", line 840, in run    signal.signal(sig, signal_handler)

There is no problem with the code, but python is having trouble adding extra threads outside the main function. Do you have any ideas how to fix this.? I am using version 3.9.12.

Thanks!

elceef commented 2 years ago

Please pull the most recent version and let me know if commit 37d0fd4 resolved the issue. Essentially dnstwist.run() should set custom signal handlers only if executed in main thread.

khantext commented 1 year ago

I invoked run in a Google Cloud Functions function earlier today and experienced the same problem that had been described in the OP: ValueError: signal only works in main thread of the main interpreter. I had not specified a specific dnstwist package version in my requirements.txt, so my assumption is that GCP installed the latest one (i.e., 20220131).

This evening I redeployed my function, removing dnstwist from my requirements.txt. I included dnstwist commit 37d0fd4f5c3569fb50e1130062e971e11b80db65 (that @elceef referenced above) along with my code and pointed to it instead. My function now runs seamlessly and produces the expected data output from dnstwist.

For my part, I consider this one solved.

FWIW, here is the full error output I originally saw: dnstwist_signal_error.txt