Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- if iswindows:
- if '--multiprocessing-fork' in sys.argv:
- # We are using the multiprocessing module on windows to launch a
- # worker process
- from multiprocessing import freeze_support
- freeze_support()
- return 0
- # Close open file descriptors inherited from parent
- # On Unix this is done by the subprocess module
- os.closerange(3, 256)
- if isosx and 'CALIBRE_WORKER_ADDRESS' not in os.environ:
- # On some OS X computers launchd apparently tries to
- # launch the last run process from the bundle
- # so launch the gui as usual
- from calibre.gui2.main import main as gui_main
- return gui_main(['calibre'])
- csw = os.environ.get('CALIBRE_SIMPLE_WORKER', None)
- if csw:
- mod, _, func = csw.partition(':')
- mod = importlib.import_module(mod)
- func = getattr(mod, func)
- func()
- return
- if '--pipe-worker' in sys.argv:
- exec (sys.argv[-1])
- return
- address = cPickle.loads(unhexlify(os.environ['CALIBRE_WORKER_ADDRESS']))
- key = unhexlify(os.environ['CALIBRE_WORKER_KEY'])
- resultf = unhexlify(os.environ['CALIBRE_WORKER_RESULT']).decode('utf-8')
- with closing(Client(address, authkey=key)) as conn:
- name, args, kwargs, desc = eintr_retry_call(conn.recv)
- if desc:
- prints(desc)
- sys.stdout.flush()
- func, notification = get_func(name)
- notifier = Progress(conn)
- if notification:
- kwargs[notification] = notifier
- notifier.start()
- result = func(*args, **kwargs)
- if result is not None and os.path.exists(os.path.dirname(resultf)):
- cPickle.dump(result, open(resultf, 'wb'), -1)
- notifier.queue.put(None)
- sys.stdout.flush()
- sys.stderr.flush()
- return 0
- if __name__ == '__main__':
- sys.exit(main())
Add Comment
Please, Sign In to add comment