Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

C-binding with multiple threads #1711

Closed
laszbalo opened this issue May 11, 2014 · 7 comments
Closed

C-binding with multiple threads #1711

laszbalo opened this issue May 11, 2014 · 7 comments

Comments

@laszbalo
Copy link

Hi,

I am trying to create a Node.js C++ binding for wkhtmltopdf.
This is what I would like to achieve:

  1. initialize wkhtmltopdf only once inside main: wkhtmltopdf_init(false);
    I assume that I can achieve some performance gain by reusing one instance of QApplication among worker threads.
  2. start a new thread for every conversion task, this way Node's main event loop won't block

My issues are the followings:

  1. after calling wkhtmltopdf_init in main, and starting the thread, it is just idling at 10%. It seems to me that the thread may see QApplication uninitialized or can not see it at all. Was wkhtmltopdf implemented that way that it can only be used in a single thread or am I doing something wrong? (nodejs uses libuv which utilizes phtread on Linux)
  2. why is 'out' a global setting instead of an object level one like 'page'? Even if I can run multiple worker threads parallel, I can not see how could I send their results into different files easily.

I know that I can use processes (I am using a node module which exactly does this) instead of threads, however, I found that approach a little slow. I reckon because of IPC and the need to start a new QApplication for every task.

Could you please shed some light on these issues?

With thanks,
Laszlo

@ashkulz
Copy link
Member

ashkulz commented May 12, 2014

I don't think that multiple Qt event loops are possible in a single process, which is what wkhtmltopdf depends upon for the conversion process. Effectively, multiple threads are not supported in a single process; this may be solved after we upgrade to Qt5 and use the QPA backend, but there is no ETA as to when that will happen.

@laszbalo
Copy link
Author

Thanks for the clarification.
My initial thought was that the Qt event loop is created when I call init_wkthmltopdf() and then this event loop will be used during the lifetime of wkthmltopdf, until a call to wkhtmltopdf_deinit(), no matter how many converters I create.

Regards,
Laszlo

@DylanYoung
Copy link

Was this ever resolved?

@ashkulz
Copy link
Member

ashkulz commented Jan 15, 2020

Unfortunately, no 🙁

@brytonbeesley
Copy link

My team is using wkhtmltopdf to print invoices in a multi-threaded context and the logo is occasionally missing. After a week of troubleshooting, the most likely explanation is that when this happens the logo asset was locked by another thread that was actively using it. Has this been resolved in wkhtmltopdf yet?

@ashkulz
Copy link
Member

ashkulz commented Aug 16, 2022

Nope, using it in a multi-threaded context is not supported as mentioned earlier.

@brytonbeesley
Copy link

Thanks for replying, @ashkulz. I refactored my code to use a multi-process mechanism (instead of multi-threaded), however, the random issue still persists. Regarding your earlier comment "that multiple Qt event loops are [not] possible in a single process", is the same true in a multi-process context as well?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants