本文整理汇总了Python中fireworks.core.launchpad.LaunchPad.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python LaunchPad.from_dict方法的具体用法?Python LaunchPad.from_dict怎么用?Python LaunchPad.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fireworks.core.launchpad.LaunchPad
的用法示例。
在下文中一共展示了LaunchPad.from_dict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bootstrap_app
# 需要导入模块: from fireworks.core.launchpad import LaunchPad [as 别名]
# 或者: from fireworks.core.launchpad.LaunchPad import from_dict [as 别名]
def bootstrap_app(*args, **kwargs):
"""Pass instead of `app` to a forking process.
This is so a server process will re-initialize a MongoDB client
connection after forking. This is useful to avoid deadlock when
using pymongo with multiprocessing.
"""
import fireworks.flask_site.app
fireworks.flask_site.app.lp = LaunchPad.from_dict(
json.loads(os.environ["FWDB_CONFIG"]))
return app(*args, **kwargs)
示例2: init_yaml
# 需要导入模块: from fireworks.core.launchpad import LaunchPad [as 别名]
# 或者: from fireworks.core.launchpad.LaunchPad import from_dict [as 别名]
def init_yaml(args):
fields = (("host", "localhost"), ("port", 27017), ("name", "fireworks"), ("username", None), ("password", None))
doc = {}
print("Please supply the following configuration values")
print("(press Enter if you want to accept the defaults)\n")
for k, v in fields:
val = input("Enter {} (default: {}) : ".format(k, v))
doc[k] = val if val else v
doc["port"] = int(doc["port"]) # enforce the port as an int
with open(args.config_file, "w") as f:
import yaml
yaml.dump(LaunchPad.from_dict(doc).to_dict(), f)
print("\nConfiguration written to {}!".format(args.config_file))
示例3: Flask
# 需要导入模块: from fireworks.core.launchpad import LaunchPad [as 别名]
# 或者: from fireworks.core.launchpad.LaunchPad import from_dict [as 别名]
from flask import Flask, render_template, request, jsonify
from flask import redirect, url_for, abort
from fireworks import Firework
from fireworks.utilities.fw_serializers import DATETIME_HANDLER
from pymongo import DESCENDING
import os, json
from fireworks.core.launchpad import LaunchPad
from flask.ext.paginate import Pagination
app = Flask(__name__)
app.use_reloader=True
hello = __name__
lp = LaunchPad.from_dict(json.loads(os.environ["FWDB_CONFIG"]))
PER_PAGE = 20
STATES = Firework.STATE_RANKS.keys()
@app.template_filter('datetime')
def datetime(value):
import datetime as dt
date = dt.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%f')
return date.strftime('%m/%d/%Y')
@app.template_filter('pluralize')
def pluralize(number, singular='', plural='s'):
if number == 1:
return singular
else:
return plural
示例4: random_launch
# 需要导入模块: from fireworks.core.launchpad import LaunchPad [as 别名]
# 或者: from fireworks.core.launchpad.LaunchPad import from_dict [as 别名]
def random_launch(lp_creds):
lp = LaunchPad.from_dict(lp_creds)
while lp.run_exists(None):
launch_rocket(lp)
time.sleep(random.random()/3+0.1)
示例5: run
# 需要导入模块: from fireworks.core.launchpad import LaunchPad [as 别名]
# 或者: from fireworks.core.launchpad.LaunchPad import from_dict [as 别名]
#.........这里部分代码省略.........
# write FW.json and/or FW.yaml to the directory
if PRINT_FW_JSON:
m_fw.to_file('FW.json', indent=4)
if PRINT_FW_YAML:
m_fw.to_file('FW.yaml')
my_spec = dict(m_fw.spec) # make a copy of spec, don't override original
my_spec["_fw_env"] = self.fworker.env
# set up heartbeat (pinging the server that we're still alive)
ping_stop = start_ping_launch(lp, launch_id)
# start background tasks
if '_background_tasks' in my_spec:
for bt in my_spec['_background_tasks']:
btask_stops.append(start_background_task(bt, m_fw.spec))
# execute the Firetasks!
for t_counter, t in enumerate(m_fw.tasks[starting_task:], start=starting_task):
checkpoint = {'_task_n': t_counter,
'_all_stored_data': all_stored_data,
'_all_update_spec': all_update_spec,
'_all_mod_spec': all_mod_spec}
Rocket.update_checkpoint(lp, launch_dir, launch_id, checkpoint)
if lp:
l_logger.log(logging.INFO, "Task started: %s." % t.fw_name)
if my_spec.get("_add_launchpad_and_fw_id"):
t.fw_id = m_fw.fw_id
if FWData().MULTIPROCESSING:
# hack because AutoProxy manager can't access attributes
t.launchpad = LaunchPad.from_dict(self.launchpad.to_dict())
else:
t.launchpad = self.launchpad
if my_spec.get("_add_fworker"):
t.fworker = self.fworker
try:
m_action = t.run_task(my_spec)
except BaseException as e:
traceback.print_exc()
tb = traceback.format_exc()
stop_backgrounds(ping_stop, btask_stops)
do_ping(lp, launch_id) # one last ping, esp if there is a monitor
# If the exception is serializable, save its details
if pdb_on_exception:
pdb.post_mortem()
try:
exception_details = e.to_dict()
except AttributeError:
exception_details = None
except BaseException as e:
if lp:
l_logger.log(logging.WARNING,
"Exception couldn't be serialized: %s " % e)
exception_details = None
try:
m_task = t.to_dict()
except:
m_task = None
m_action = FWAction(stored_data={'_message': 'runtime error during task',