[erlang-questions] Using 'monitor' with spawn_opt/3 throws badarg. How to monitor a remote process?
Christopher Phillips
lostcolony@REDACTED
Thu Feb 26 06:31:12 CET 2015
For the first question (responding to both 'cause it's easier), I think it
actually just doesn't work across nodes; if I supply node() as the param,
spawn_opt/5 works just fine with monitor. Though yes, spawn_opt/3 is
probably the same issue, in that it delegates to spawn_opt/5. I bet both
are related to the fact that spawn_monitor doesn't accept a node option;
the distribution protocol probably does not handle spawning and monitoring
across nodes in an atomic fashion.
For the second, could you trap exit signals and spawn_link, and then
handle the exit messages? If an exit is from any other pid, or from the
spawned one for a reason other than normal you can disable trapping exits
and then exit for the received reason, but if it's from the spawned pid and
normal you know it completed successfully, and you can then disable
trapping exits, do a quick receive {'EXIT', ...} after 0 -> ok end in case
of any new exit messages between handling the normal exit and disabling
trapping, and then have the process go about its business.
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 23 Feb 2015 15:17:41 +0000
> From: Roger Lipscombe <roger@REDACTED>
> To: "erlang-questions@REDACTED" <erlang-questions@REDACTED>
> Subject: [erlang-questions] Using 'monitor' with spawn_opt/3 throws
> badarg. Documentation bug?
> Message-ID:
> <
> CAJgnQd8UOZzY0kPyix0oRUygw8cC-KB8ZuhJfGyq7zX-U6u_ZQ@REDACTED>
> Content-Type: text/plain; charset=UTF-8
>
> I'm attempting to use spawn_opt/3 with a remote node, like this:
>
> Fun = fun() -> ok end,
> {Pid, Ref} = spawn_opt(Node, Fun, [link, monitor]).
>
> It fails with:
>
> {badarg,
> [{erlang,spawn_opt,
> ['imp_server@REDACTED',erlang,apply,
> [#Fun<erl_eval.20.80484245>,[]],
> [link,monitor]],
> []}
>
> Now, the documentation at
> http://www.erlang.org/doc/man/erlang.html#spawn_opt-5 says that the
> 'monitor' option is not allowed for spawn_opt/5. It says nothing about
> spawn_opt/3.
>
> Looking at the error message, it looks like spawn_opt/3 simply calls
> spawn_opt/5. Does this note about 'monitor' being unsupported need to
> be in documentation for both functions?
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 23 Feb 2015 15:21:12 +0000
> From: Roger Lipscombe <roger@REDACTED>
> To: "erlang-questions@REDACTED" <erlang-questions@REDACTED>
> Subject: [erlang-questions] Using 'monitor' with spawn_opt/3 throws
> badarg. How to monitor a remote process?
> Message-ID:
> <
> CAJgnQd8t-RASC6RiJUTtfcFojp0KZVrWev4hpf7CAeOnD4pbow@REDACTED>
> Content-Type: text/plain; charset=UTF-8
>
> Note that, despite the preamble, this is a different question to the
> other one I just posted. Honest.
>
> I'm attempting to use spawn_opt/3 with a remote node, like this:
>
> Fun = fun() -> ok end,
> {Pid, Ref} = spawn_opt(Node, Fun, [link, monitor]).
>
> It fails with badarg.
>
> How do I monitor a process that I spawn on a remote node?
>
> If I use spawn_link followed by monitor, there's a race where the
> remote process could have exited already, and I get {'DOWN', Ref,
> process, Pid, noproc}, which is disconcerting.
>
> I want to know when it's finished. Preferably without it needing to
> explicitly send a message back to me.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150226/4773fbcf/attachment.htm>
More information about the erlang-questions
mailing list