<@ULVA73B9P> im trying to run an async function as...
# ask-marvin
w
@Marvin im trying to run an async function as part of a task and getting the below error using pyppeteer ValueError: signal only works in main thread of the main interpreter
m
It seems that you have encountered a threading issue while trying to use
pyppeteer
asynchronously within a task. This particular error occurs because Python's
signal
module does not allow setting new signal handlers outside the main thread, and
pyppeteer
attempts to set a
SIGINT
handler when it is launched. Here’s a relevant GitHub issue from the
pyppeteer
repository that discusses a similar error: Can't run pyppeteer with Threads? - ValueError: signal only works in main thread of the main interpreter. The issue suggests that the use of threads in conjunction with
pyppeteer
can lead to this error. There isn't a direct solution from the Prefect documentation available at the moment, but a common workaround for issues like this involves running the offending code in a separate process rather than in a thread. You might consider using Python’s
multiprocessing
module or run the
pyppeteer
code within a dedicated executor using
concurrent.futures.ProcessPoolExecutor
to avoid clashes with signal handling in the main thread. Please check the linked GitHub issue for more context, and you may want to consider looking into process-based parallelism or the proper use of asynchronous and synchronous code in Prefect tasks to resolve the issue you're facing.
n
i would not use multiprocessing here, I would just run your pyppeteer stuff in a subflow so its in the main thread
but marvin seems correct about the diagnosis