【问题标题】:Start GProc as a dependency启动 GProc 作为依赖项
【发布时间】:2016-07-21 19:10:55
【问题描述】:

我正在尝试将 gproc 作为应用程序内的 依赖项 启动,但它失败了:

{error,{not_started,gproc}}

这是 Rebar3 在编译时使用的 app.src 文件:

{application, myapp,
 [{description, "MyApp"},
  {vsn, "0.1.0"},
  {registered, []},
  {mod, { my_app, []}},
  {applications,
   [kernel,
    stdlib,
    sasl,
    gproc    <--- Dependency, and is compiled with Rebar3
   ]},
  {env,[]},
  {modules, []},

  {maintainers, []},
  {licenses, []},
  {links, []}
 ]}.

当从 shell 开始使用 application:start(gproc). 然后 application:start(myapp). 一切正常。我不明白为什么...

也许是因为某种竞争条件?

shell 开始于:

erl -pa _build/default/lib/*/ebin -boot start_sasl -eval "application:start(myapp)"

编辑:当使用rebar3 shell时一切正常,与我使用的shell命令有什么区别?

【问题讨论】:

    标签: erlang rebar3


    【解决方案1】:

    使用

    application:ensure_all_started(myapp).
    

    普通的start 尝试仅启动请求的应用程序,仅验证依赖项是否已在运行。

    文档:

    • application:start/1:

      启动应用程序。如果没有加载,应用程序控制器首先使用 load/1 加载它。它确保加载任何包含的应用程序,但不会启动它们。假定在 Application 的代码中已经处理了这一点。

    • application:ensure_all_started/1

      相当于对应用程序尚未启动的所有依赖项重复调用 start/1,2

    【讨论】:

    猜你喜欢
    • 2015-04-21
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 2019-09-02
    • 1970-01-01
    • 2016-11-03
    相关资源
    最近更新 更多