erlang

Erlang tracing (collect data from processes only in my modules)

非 Y 不嫁゛ 提交于 2019-12-13 04:01:14
问题 While tracing my modules using dbg, I encountered with the problem how to collect messages such as spawn, exit, register, unregister, link, unlink, getting_linked, getting_unlinked, which are allowed by erlang:trace, but only for those processes which were spawned from my modules directly? As an examle I don't need to know which processes io module create, when i call io:format in some module function. Does anybody know how to solve this problem? 回答1: Short answer: one way is to look at call

ct_netconfc:open/1 raises an “exception error: bad argument”

送分小仙女□ 提交于 2019-12-13 03:12:49
问题 I wrote this Erlang module: -module(ncclient). -export([open/0]). open() -> Host = {ssh, {192,168,30,11}}, Port = {port, 830}, User = {user, "admin"}, Pass = {password, "admin"}, ct_netconfc:open([Host, Port, User, Pass]). Compiled, then ran it: # erl Erlang/OTP 20 [erts-9.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [kernel-poll:false] Eshell V9.1 (abort with ^G) 1> c(ncclient). {ok,ncclient} 2> ncclient:open(). ** exception error: bad argument in function ets:select/2

How to build and use epgsql (erlang)

强颜欢笑 提交于 2019-12-13 02:56:47
问题 My erlang program directory structure is below: src pgtest.erl lib epgsql rebar I downloaded the epgsql library from https://github.com/epgsql/epgsql then tried to build it with make which gave me the below error: make: rebar: Command not found make: *** [compile] Error 127 So then I downloaded rebar from https://github.com/basho/rebar and build it. It was build successfully and gave me the message. Congratulations! You now have a self-contained script called "rebar" in your current working

How to run a set of TWEANN benchmarks in Erlang correctly?

别来无恙 提交于 2019-12-13 02:37:32
问题 I've been reading Gene I Sher's Handbook to neuroevolution through Erlang and trying to replicate all the experiments described there. And it all worked, until I came to chapter 19, which read Having set everything up, we execute the benchmark for every noted experimental setup, and run it to completion. To do this, we simply modify the constraints used in our benchmarker module, and then execute benchmarker:start(Experiment_Name) , for every of our experimental setups. There are 14

Erlang “Kernel pid terminated” error

。_饼干妹妹 提交于 2019-12-13 02:04:51
问题 I try to use relx for release application. Relx did it without problems. But when I start application, I have the error: {"Kernel pid terminated",application_controller," {application_start_failure,iqServer,{bad_return,{{iqServer_app,start,[normal,[]]}, {'EXIT',{undef,[{iqServer_app,start,[normal,[]],[]}, {application_master,start_it_old,4,[{file,\"application_master.erl\"}, {line,272}]}]}}}}}"} As I understand from the error, I have a problem in the function iqServer:start/2 . start/2 looks

Simulation of Thread Pool for a web-server implemented by Erlang doesn't work

旧时模样 提交于 2019-12-13 01:36:20
问题 The code is as follows: -module(rudy). -export([init/1,handler/1,request/1,reply/1, start/1, stop/0]). start(Port) -> register(rudy, spawn(fun() -> init(Port) end)). stop() -> exit(whereis(rudy), "time to die"). init(Port) -> Opt = [list, {active, false}, {reuseaddr, true}], case gen_tcp:listen(Port, Opt) of % opens a listening socket {ok, Listen} -> spawn_many(3,Listen), %% handler(Listen), ok; {error, _Error} -> error end. handler(Listen) -> case gen_tcp:accept(Listen) of % listen to the

How to find all possible pairs from three subsets of a set with constraints in Erlang?

蹲街弑〆低调 提交于 2019-12-13 01:19:06
问题 I have a set M which consists of three subsets A,B and C. Problem: I would like to calculate all possible subsets S(1)...S(N) of M which contain all possible pairs between elements of A, B and C in such manner that: elements of A and B can happen in a pair only once for each of two positions in a pair (that is {a1,a2} and {b1,a1} can be in one subset S, but no more elements {a1,_} and {_,a1} are allowed in this subset S); elements of C can happen 1-N times in a subset S (that is {a,c}, {b,c},

Erlang message to non-existent PID

纵饮孤独 提交于 2019-12-13 01:07:04
问题 What does the Erlang runtime do with a message sent to a non-existent process? For example, a process is spawned, and then later after it terminates another process sends a message to it. 回答1: The message is dropped. Per the documentation: If the receiver has terminated, the signal will not arrive... Also see this answer from rvirding, who probably knows what he's talking about: While sending a message to a pid which refers to a dead process is perfectly legal (the message just disappears)...

Can I use an existing OTP application inside another application or module?

扶醉桌前 提交于 2019-12-12 19:56:26
问题 I'm building a system that needs to use a previously built OTP application (lets call it X). If I want to build a new OTP application / module, how can I use the application that already exists from a module, for instance? I assumed I could call start , since it follows the application behaviour, and so I built a minimalistic application Y that has the following code: y.erl: -module(y). -behaviour(application). start(_StartType, _StartArgs) -> io:format("going to call x_app~n"), {ok, _} = x

How can I pattern match in a function where a Map has a key with the passed in value?

独自空忆成欢 提交于 2019-12-12 19:24:48
问题 So I am creating an IRC server, and I have a function that removes a user from a Map. The idea is to use pattern matching, so one version of a function gets called if the user is in the map and another function gets called otherwise. My first idea was to do the following: remove_user_from_channel(User, Channel=#channel_details{users = UserMap=#{User := _}}) -> Channel#channel_details{users = maps:remove(User, UserMap)}. However, this fails to compile with the error variable 'User' is unbound