julenuri

Calibre Windows MP

Nov 19th, 2020 (edited)
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. def main():
  2.     if iswindows:
  3.         if '--multiprocessing-fork' in sys.argv:
  4.             # We are using the multiprocessing module on windows to launch a
  5.             # worker process
  6.             from multiprocessing import freeze_support
  7.             freeze_support()
  8.             return 0
  9.         # Close open file descriptors inherited from parent
  10.         # On Unix this is done by the subprocess module
  11.         os.closerange(3, 256)
  12.     if isosx and 'CALIBRE_WORKER_ADDRESS' not in os.environ:
  13.         # On some OS X computers launchd apparently tries to
  14.         # launch the last run process from the bundle
  15.         # so launch the gui as usual
  16.         from calibre.gui2.main import main as gui_main
  17.         return gui_main(['calibre'])
  18.     csw = os.environ.get('CALIBRE_SIMPLE_WORKER', None)
  19.     if csw:
  20.         mod, _, func = csw.partition(':')
  21.         mod = importlib.import_module(mod)
  22.         func = getattr(mod, func)
  23.         func()
  24.         return
  25.     if '--pipe-worker' in sys.argv:
  26.         exec (sys.argv[-1])
  27.         return
  28.     address = cPickle.loads(unhexlify(os.environ['CALIBRE_WORKER_ADDRESS']))
  29.     key     = unhexlify(os.environ['CALIBRE_WORKER_KEY'])
  30.     resultf = unhexlify(os.environ['CALIBRE_WORKER_RESULT']).decode('utf-8')
  31.     with closing(Client(address, authkey=key)) as conn:
  32.         name, args, kwargs, desc = eintr_retry_call(conn.recv)
  33.         if desc:
  34.             prints(desc)
  35.             sys.stdout.flush()
  36.         func, notification = get_func(name)
  37.         notifier = Progress(conn)
  38.         if notification:
  39.             kwargs[notification] = notifier
  40.             notifier.start()
  41.  
  42.         result = func(*args, **kwargs)
  43.         if result is not None and os.path.exists(os.path.dirname(resultf)):
  44.             cPickle.dump(result, open(resultf, 'wb'), -1)
  45.  
  46.         notifier.queue.put(None)
  47.  
  48.     sys.stdout.flush()
  49.     sys.stderr.flush()
  50.     return 0
  51.  
  52.  
  53. if __name__ == '__main__':
  54.     sys.exit(main())
Add Comment
Please, Sign In to add comment