Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 08-10-2021, 10:12 PM   #1
xxyzz
Evangelist
xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.
 
Posts: 440
Karma: 2666666
Join Date: Nov 2020
Device: none
Terminate process in ThreadedJob terminates calibre main process

I was using spaCy's multiprocessing pipe(https://github.com/explosion/spaCy/b...guage.py#L1581) in ThreadedJob but found it will terminate calibre, I think the code should looks like this:

Code:
from multiprocessing import Process
from threading import Thread

def fun():
    while True:
        pass

class JobThread(Thread):
    def run(self):
        # code in ThreadedJob
        p = Process(target=fun)
        p.start()
        p.terminate()

JobThread().start()  # pretend it's ThreadedJobServer
The process created in ThreadedJob is still running but the calibre main process is terminated.

I also want to know the difference between calibre's ParallelJob and ThreadedJob.
xxyzz is offline   Reply With Quote
Old 08-10-2021, 10:16 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,195
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
What is it yu are actually trying to do?
kovidgoyal is offline   Reply With Quote
Advert
Old 08-10-2021, 10:25 PM   #3
xxyzz
Evangelist
xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.
 
Posts: 440
Karma: 2666666
Join Date: Nov 2020
Device: none
I just want to try spaCy's multiprocessing pipe feature, and I put run the code inside ThreadJob to prevent these code to freeze calibre. If enable spacy's multiprocessing mode, it will create some processes run a `while` loop then terminate them when they are done. But these processes are still running and calibre is terminated instead.

I don't understand why sending SIGTERM to these processes somehow terminates calibre.

Last edited by xxyzz; 08-10-2021 at 10:41 PM.
xxyzz is offline   Reply With Quote
Old 08-10-2021, 10:45 PM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,195
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Presumably it is sending SIGTERM to the main calibre process instead.
kovidgoyal is offline   Reply With Quote
Old 08-10-2021, 10:52 PM   #5
xxyzz
Evangelist
xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.
 
Posts: 440
Karma: 2666666
Join Date: Nov 2020
Device: none
But shouldn't `p.terminate()` send the signal just to `p`?
xxyzz is offline   Reply With Quote
Advert
Old 08-10-2021, 11:11 PM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,195
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You cannot use multiprocessing safely in native code programs (such as calibre) that embed a python interpreter. In fact, you cant use it safely at all, it is one of the worst designed modules in the standard library. Read its docs, in particular

The 'spawn' and 'forkserver' start methods cannot currently be used with “frozen” executables (i.e., binaries produced by packages like PyInstaller and cx_Freeze) on Unix. The 'fork' start method does work.

And fork is broken in any program that uses threading anyway. So multiprocessing is a complete no go.

Again, let me ask, what it is you want to actually do. calibre already has the ability to run worker processes in several ways. It does not however touch multiprocessing with ten foot barge pole.
kovidgoyal is offline   Reply With Quote
Old 08-10-2021, 11:26 PM   #7
xxyzz
Evangelist
xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.xxyzz ought to be getting tired of karma fortunes by now.
 
Posts: 440
Karma: 2666666
Join Date: Nov 2020
Device: none
I'm using spacy's `nlp.pipe()` to find named entities in the book text, this function has a parameter 'n_process' to set how many processes to run this function. The default value is 1 and no process is created. I want to see whether enable multiprocessing will be faster.

Oh, I don't know fork a multithreaded process is problematic as the doc says.

And could you please explain the difference between ParallelJob and ThreadedJob?
xxyzz is offline   Reply With Quote
Old 08-10-2021, 11:34 PM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,195
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
ParallelJob is designed to work with pre-defined entry points in ipc/worker.py that are run in worker processes. ThreadedJob is meant for in-process jobs.

However, either of these classes are meant to be used only with calibre's jobs system (the jobs button in the main calibre gui). If you want to do jobs in multiple processes as part of larger job, your best bet is to use the ipc/simple_worker.py module. See for example how it is used in srv/render_book.py where calibre uses multiple worker processes to transform a book into a form suitable for the calibre viewer.
kovidgoyal is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calibre's Updating Process - In Need of an overhaul m113t Calibre 2 01-05-2018 10:19 PM
Calibre In Process Server help DouglasK Related Tools 12 04-30-2014 01:45 AM
Process Still Active after Calibre Closed country0129 Calibre 0 06-16-2012 08:16 AM
"The process android.process.acore has stopped unexpectedly. Please try again." Cdesja5 Kobo Tablets 2 01-03-2012 11:31 AM
Calibre Internal Process While Updating Evilwarning Calibre 13 12-17-2010 04:26 PM


All times are GMT -4. The time now is 12:19 AM.


MobileRead.com is a privately owned, operated and funded community.