How to use the pykern.pkdebug.pkdexc function in pykern

To help you get started, we’ve selected a few pykern examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github radiasoft / sirepo / sirepo / job_agent_process.py View on Github external
stderr=tornado.process.Subprocess.STREAM,
        env=env,
    )
    try:
        async def collect(stream, out_array):
            out_array += await stream.read_until_close()
        r = PKDict(
            stdout=bytearray(),
            stderr=bytearray(),
        )
        i = tornado.ioloop.IOLoop.current()
        i.spawn_callback(collect, p.stdout, r.stdout)
        i.spawn_callback(collect, p.stderr, r.stderr)
        r.returncode = await p.wait_for_exit(raise_error=False)
    except Exception:
        pkdlog(pkdexc())
    finally:
        p.proc.kill()
    return r
github radiasoft / sirepo / sirepo / template / srw.py View on Github external
xih = crystal_parameters['xih']
        elif re.search('(SRW)', material_raw):
            dc = srwl_uti_cryst.srwl_uti_cryst_pl_sp(millerIndices, material)
            xr0, xi0, xrh, xih = srwl_uti_cryst.srwl_uti_cryst_pol_f(energy, millerIndices, material)
        else:
            dc = xr0 = xi0 = xrh = xih = None

        model['dSpacing'] = dc
        model['psi0r'] = xr0
        model['psi0i'] = xi0
        model['psiHr'] = xrh
        model['psiHi'] = xih
        model['psiHBr'] = xrh
        model['psiHBi'] = xih
    except Exception:
        pkdlog('{}: error: {}', material_raw, pkdexc())
        for key in parms_list:
            model[key] = None

    return model
github radiasoft / sirepo / sirepo / srunit.py View on Github external
):
                raise sirepo.util.SRException(
                    d.srException.routeName,
                    d.srException.params,
                )
            return d
        except Exception as e:
            if not isinstance(e, (sirepo.util.Reply)):
                pkdlog(
                    'Exception: {}: msg={} uri={} status={} data={} stack={}',
                    type(e),
                    e,
                    u,
                    r and r.status_code,
                    r and r.data,
                    pkdexc(),
                )
            raise
github radiasoft / sirepo / sirepo / runner / docker.py View on Github external
jid = m.group(2)
                assert not jid in res, \
                    '{}: duplicate jid on ({},{}) and {}'.format(
                        jid,
                        h,
                        i,
                        res[jid],
                    )
                res[jid] = pkcollections.Dict(host=h, cid=i, jid=jid)
        except Exception as e:
            # Can't do anything except log and try to recover at next poll
            pkdlog(
                '{}: PROGRAM ERROR: unexpected docker ps: {}\n{}',
                h,
                e,
                pkdexc(),
            )
    return res
github radiasoft / sirepo / sirepo / simulation_db.py View on Github external
),
            ))
        util.raise_not_found(
            '{}/{}: global simulation not found',
            sim_type,
            sid,
        )
    data = None
    try:
        with open(str(path)) as f:
            data = json_load(f)
            # ensure the simulationId matches the path
            if sid:
                data.models.simulation.simulationId = _sim_from_path(path)[0]
    except Exception as e:
        pkdlog('{}: error: {}', path, pkdexc())
        raise
    return fixup_old_data(data)[0] if fixup else data
github radiasoft / sirepo / sirepo / simulation_db.py View on Github external
data.simulationType = 'elegant'
            else:
                pkdlog('simulationType: not found; data={}', data)
                raise AssertionError('must have simulationType')
        elif data.simulationType == 'warp':
            data.simulationType = 'warppba'
        elif data.simulationType == 'fete':
            data.simulationType = 'warpvnd'
        if 'simulationSerial' not in data.models.simulation:
            data.models.simulation.simulationSerial = 0
        import sirepo.sim_data
        sirepo.sim_data.get_class(data.simulationType).fixup_old_data(data)
        data.pkdel('fixup_old_version')
        return data, True
    except Exception as e:
        pkdlog('exception={} data={} stack={}', e, data, pkdexc())
        raise
github radiasoft / sirepo / sirepo / job_driver / __init__.py View on Github external
w = self.websocket
            self.websockt = None
            if w:
                # Will not call websocket_on_close()
                w.sr_close()
            t = list(
                self.ops_pending_done.values()
                )
            t.extend(self.ops_pending_send)
            self.ops_pending_done.clear()
            self.ops_pending_send = []
            for o in t:
                o.set_errored('websocket closed')
            self.run_scheduler(self)
        except Exception as e:
            pkdlog('error={} stack={}', e, pkdexc())
github radiasoft / sirepo / sirepo / template / template_common.py View on Github external
from sirepo import simulation_db

    frame_args.pksetdefault(
        run_dir=lambda: simulation_db.simulation_run_dir(frame_args),
    ).pksetdefault(
        sim_in=lambda: simulation_db.read_json(
            frame_args.run_dir.join(INPUT_BASE_NAME),
        ),
    )
    t = sirepo.template.import_module(frame_args.simulationType)
    o = getattr(t, 'sim_frame', None) \
        or getattr(t, 'sim_frame_' + frame_args.frameReport)
    try:
        res = o(frame_args)
    except Exception as e:
        pkdlog('error generating report frame_args={} stack={}', frame_args, pkdexc())
        raise sirepo.util.convert_exception(e, display_text='Report not generated')
    if res is None:
        raise RuntimeError('unsupported simulation_frame model={}'.format(frame_args.frameReport))
    return res
github radiasoft / sirepo / sirepo / runner / docker.py View on Github external
"""Kill any jobs that might be running at init
    """
#TODO(robnagler) parse the jobs and re-insert into jobs and slots.
    hosts = [h.name for h in _hosts_ordered]
    containers = _parse_ps(hosts, _CNAME_PREFIX)
    for c in containers.values():
        try:
            pkdlog('{jid}@{host}: stopping container', **c)
            o = _cmd(c.host, ('rm', '--force', c.cid))
        except Exception as e:
            # Can't do anything except log and try to recover at next poll
            pkdlog(
                '{}: unexpected docker rm output: {}\n{}',
                c.host,
                e,
                pkdexc(),
            )