def is_in_docplex_worker(): try: import docplex.worker.solvehook as worker_env hook = worker_env.get_solve_hook() if hook: return True except ImportError: pass return False
def _get_default_environment(): # creates a new instance of the default environment try: import docplex.worker.solvehook as worker_env hook = worker_env.get_solve_hook() if hook: return WorkerEnvironment(hook) except ImportError: pass return LocalEnvironment()
def set_stop_callback(cb): env = get_environment() try: env.set_stop_callback(cb) except AttributeError: # env.set_stop_callback does not exists -> older version of docplex # use work around try: import docplex.worker.solvehook as worker_env hook = worker_env.get_solve_hook() if hook: hook.set_stop_callback(cb) finally: # ignore errors pass