学习Erlang? speedbump线程,常见,小问题 [英] Learning Erlang? speedbump thread, common, small problems

查看:110
本文介绍了学习Erlang? speedbump线程,常见,小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,这里是第一个speedbumps我在...之前,我只想知道你和最终解决方案之间所有的小问题。有:


  1. 如果您在多个线程中产生,请使用controls_process(Socket,Pid)。正确的分组到正确的线程。

  2. 您要开始与其他服务器通话?记住net_adm:ping('car @ bsd-server')。在壳里。否则没有沟通将会通过。

  3. 计时器:睡眠(10),如果你不想做任何事情。调试时始终有用


解决方案


  • 学习浏览标准文档



    一旦您了解OTP文档的组织方式,您将更容易找到所需内容(您倾向于了解哪些应用程序提供哪些模块或类型模块)。



    还只是浏览应用程序的文档通常是非常有益的 - 我已经发现了许多非常有用的代码 - sys dbg 工具栏等。


  • shell erlang和模块erlang之间的区别



    Shell erlang是模块erlang的一个稍微不同的方言。您无法定义模块功能(仅限乐趣),您需要加载记录定义才能处理记录( rr / 1 )等等。学习如何用匿名函数编写erlang代码有点棘手,但是对于使用远程shell处理生产系统是至关重要的。



    学习shell和{start,spawn} _link ed进程 - 当您运行一些崩溃的shell代码(引发异常)时,shell进程退出并将向您链接的任何内容发送退出信号。这将反过来关闭您正在处理的新gen_server。 (为什么我的服务器进程不断消失?


  • erlang表达式与保护表达式之间的区别



    保护表达式(when子句)不是Erlang表达式。他们可能看起来很相似,但是差别很大。守卫不能调用任意erlang函数,只能保护函数( length / 1 ,类型测试 element / 2 和a OTP文档中指定的其他几个)。卫兵成功或失败,没有副作用。


  • 代码加载



    工作时间并且代码升级如何工作,咒骂得到gen_server升级到最新版本的回调模块( code:load(Mod),sys:suspend(Pid),sys:change_code(Pid,Mod ,未定义,未定义),sys:resume(Pid)。)。



    代码服务器路径( get_path / 0 ) - 我无法计算多少次我遇到未定义的函数错误,原来是我忘记添加一个ebin目录到代码搜索路径。


  • 构建erlang代码



    制定一个有用的组合emake( make:all / 0 erl -make )和gnu make花了相当长的时间(到目前为止已经有三年了):



    我现在最喜欢的makefile可以在 http://github.com/archaelus / esmtp / tree / master


  • Erlang发行



    获取节点名称,dns,cookies以及所有其余的权限,以便能够 net_adm:ping / 1 另一个节点。这需要练习。


  • 远程外壳IO复杂



    记住通过 group_leader() io:format 调用在远程节点上运行,以使输出出现在你的shell中,而不是神秘地消失(认为SASL报告浏览器 rb 在通过远程shell连接使用时将某些输出发送到错误的节点仍然存在问题



I just want know all the small problems that got between you and your final solution when you were new to Erlang.

For example, here are the first speedbumps I had:

  1. Use controlling_process(Socket, Pid) if you spawn off in multiple threads. Right packet to the right thread.
  2. You going to start talking to another server? Remember to net_adm:ping('car@bsd-server'). in the shell. Else no communication will get through.
  3. Timer:sleep(10), if you want to do nothing. Always useful when debugging.

解决方案

  • Learning to browse the standard documentation

    Once you learn how the OTP documentation is organised it becomes much easier to find what you're looking for (you tend to need to learn which applications provide which modules or kinds of modules).

    Also just browsing the documentation for applications is often quite rewarding - I've discovered lots of really useful code this way - sys, dbg, toolbar, etc.

  • The difference between shell erlang and module erlang

    Shell erlang is a slightly different dialect to module erlang. You can't define module functions (only funs), you need to load record definitions in order to work with records (rr/1) and so on. Learning how to write erlang code in terms of anonymous functions is somewhat tricky, but is essential for working on production systems with a remote shell.

    Learning the interaction between the shell and {start,spawn}_link ed processes - when you run some shell code that crashes (raises an exception), the shell process exits and will broadcast exit signals to anything you linked to. This will in turn shut down that new gen_server you're working on. ("Why does my server process keep disappearing?")

  • The difference between erlang expressions and guard expressions

    Guard expressions (when clauses) are not Erlang expressions. They may look similar, but they're quite different. Guards cannot call arbitrary erlang functions, only guard functions (length/1, the type tests, element/2 and a few others specified in the OTP documentation). Guards succeed or fail and don't have side effects. Erlang expressions on the other hand can do what they like.

  • Code loading

    Working out when and how code upgrades work, the incantation to get a gen_server to upgrade to the latest version of a callback module (code:load(Mod), sys:suspend(Pid), sys:change_code(Pid, Mod, undefined, undefined), sys:resume(Pid).).

    The code server path (code:get_path/0) - I can't count how many times I ran into undefined function errors that turned out to be me forgetting to add an ebin directory to the code search path.

  • Building erlang code

    Working out a useful combination of emake (make:all/0 and erl -make) and gnu make took quite a long time (about three years so far :).

    My current favourite makefiles can be seen at http://github.com/archaelus/esmtp/tree/master

  • Erlang distribution

    Getting node names, dns, cookies and all the rest right in order to be able to net_adm:ping/1 the other node. This takes practise.

  • Remote shell IO intricacies

    Remembering to pass group_leader() to io:format calls run on the remote node so that the output appears in your shell rather than mysteriously disappearing (I think the SASL report browser rb still has a problem with sending some of its output to the wrong node when used over a remote shell connection)

这篇关于学习Erlang? speedbump线程,常见,小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆