折りたたみロードバイクReach R20
DRbでプロセスをまたがった大域脱出ができるか確認した
結論としてはできなかった。
Rubyのバージョン:
$ ruby -v ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]
確認用のコード:
require 'drb/drb' require 'drb/unix' require 'logger' stdlog = Logger.new(STDOUT) module Jump def ping yield('pong') end module_function :ping def occur(tag, value) throw(tag, value) end module_function :occur end druby_local_uri = 'drbunix:' + File.expand_path(File.join(File.dirname($0), "druby_local.#{$$}")) druby_remote_uri = 'drbunix:' + File.expand_path(File.join(File.dirname($0), "druby_remote.#{$$}")) stdlog.info("start local dRuby service: #{druby_local_uri}") DRb.start_service(druby_local_uri) pid = fork{ stdlog.info("start remote dRuby service: #{druby_remote_uri}") DRb.start_service(druby_remote_uri, Jump) DRb.thread.join } at_exit{ Process.kill('TERM', pid) } drb_remote_obj = DRbObject.new_with_uri(druby_remote_uri) stdlog.info('wait to start dRuby services') begin t0 = Time.now begin drb_remote_obj.ping{|r| r == 'pong' or raise 'failed ping.' } rescue DRb::DRbConnError if (Time.now - t0 >= 10) then raise end sleep(0.1) retry end rescue stdlog.fatal('failed to start dRuby services') stdlog.fatal($!) abort end stdlog.info('local jump test') begin r = catch(:foo) { Jump.occur(:foo, 'local_jump_test') nil } r == 'local_jump_test' or raise 'failed local jump test.' rescue stdlog.error('NG') stdlog.error($!) else stdlog.info('OK') end stdlog.info('remote jump test') begin r = catch(:bar) { drb_remote_obj.occur(:bar, 'remote_jump_test') nil } r == 'remote_jump_test' or raise 'failed remote jump test.' rescue stdlog.error('NG') stdlog.error($!) else stdlog.info('OK') end
確認結果:
$ ./druby_ipc_jump.rb I, [2019-04-12T00:25:00.940801 #4402] INFO -- : start local dRuby service: drbunix:/home/toki/git_work/ruby_examples/druby_local.4402 I, [2019-04-12T00:25:00.962852 #4402] INFO -- : wait to start dRuby services I, [2019-04-12T00:25:00.964105 #4404] INFO -- : start remote dRuby service: drbunix:/home/toki/git_work/ruby_examples/druby_remote.4402 I, [2019-04-12T00:25:01.072707 #4402] INFO -- : local jump test I, [2019-04-12T00:25:01.083738 #4402] INFO -- : OK I, [2019-04-12T00:25:01.083973 #4402] INFO -- : remote jump test E, [2019-04-12T00:25:01.100414 #4402] ERROR -- : NG E, [2019-04-12T00:25:01.100528 #4402] ERROR -- : uncaught throw :bar (UncaughtThrowError) (drbunix:/home/toki/git_work/ruby_examples/druby_remote.4402) ./druby_ipc_jump.rb:17:in `throw' (drbunix:/home/toki/git_work/ruby_examples/druby_remote.4402) ./druby_ipc_jump.rb:17:in `occur' (drbunix:/home/toki/git_work/ruby_examples/druby_remote.4402) /usr/local/lib/ruby/2.6.0/drb/drb.rb:1635:in `perform_without_block' (drbunix:/home/toki/git_work/ruby_examples/druby_remote.4402) /usr/local/lib/ruby/2.6.0/drb/drb.rb:1595:in `perform' (drbunix:/home/toki/git_work/ruby_examples/druby_remote.4402) /usr/local/lib/ruby/2.6.0/drb/drb.rb:1679:in `block (2 levels) in main_loop' (drbunix:/home/toki/git_work/ruby_examples/druby_remote.4402) /usr/local/lib/ruby/2.6.0/drb/drb.rb:1675:in `loop' (drbunix:/home/toki/git_work/ruby_examples/druby_remote.4402) /usr/local/lib/ruby/2.6.0/drb/drb.rb:1675:in `block in main_loop' ./druby_ipc_jump.rb:77:in `block in <main>' ./druby_ipc_jump.rb:76:in `catch' ./druby_ipc_jump.rb:76:in `<main>'
RubyのUncaughtThrowError
は大域脱出のtag
とvalue
の値を持つのでハンドリングできそうなものだが実装されてないのかな。
3月に読んだ本やマンガ
3月の読書メーター
読んだ本の数:24
読んだページ数:4193
ナイス数:0
天竺熱風録 5 (ヤングアニマルコミックス)
読了日:03月01日 著者:伊藤勢
明治撃剣会 (文春文庫)
読了日:03月01日 著者:津本 陽
NHK「100分de名著」ブックス 孔子 論語
読了日:03月03日 著者:佐久 協
NHK「100分de名著」ブックス 古事記
読了日:03月03日 著者:三浦 佑之
父とヒゲゴリラと私 6 (バンブーコミックス)
読了日:03月06日 著者:小池 定路
父とヒゲゴリラと私 7 完結 (バンブーコミックス)
読了日:03月06日 著者:小池 定路
誰もが嘘をついている ビッグデータ分析が暴く人間のヤバい本性
読了日:03月07日 著者:セス・スティーヴンズ=ダヴィドウィッツ
ダーウィンズゲーム(17) (少年チャンピオン・コミックス)
読了日:03月08日 著者:FLIPFLOPs
大乗仏教―ブッダの教えはどこへ向かうのか (NHK出版新書 572)
読了日:03月11日 著者:佐々木 閑
年上の物理女子は可愛いと思いませんか? (1) (まんがタイムコミックス)
読了日:03月11日 著者:ミツナナエ
文系のための数学教室 (講談社現代新書)
読了日:03月12日 著者:小島 寛之
ブラック・ジャック~青き未来~ (少年チャンピオン・コミックスエクストラ)
読了日:03月12日 著者:手塚 治虫
うわばみ彼女 (ジェッツコミックス)
読了日:03月12日 著者:後藤羽矢子
うわばみ彼女 2 (ジェッツコミックス)
読了日:03月14日 著者:後藤羽矢子
地球46億年 気候大変動 炭素循環で読み解く、地球気候の過去・現在・未来 (ブルーバックス)
読了日:03月17日 著者:横山 祐典
続・ゆかいな仏教 (サンガ新書 72)
読了日:03月19日 著者:橋爪大三郎,大澤真幸
魔法少女特殊戦あすか(10) (ビッグガンガンコミックス)
読了日:03月26日 著者:深見 真,刻夜セイゴ
はじめての技術書ライティング―IT系技術書を書く前に読む本 (NextPublishing)
読了日:03月26日 著者:向井 領治
進化心理学から考えるホモサピエンス 一万年変化しない価値観 (フェニックスシリーズ)
読了日:03月28日 著者:アラン・S・ミラー
うわばみ彼女 3 (ヤングアニマルコミックス)
読了日:03月29日 著者:後藤羽矢子
うわばみ彼女 4 (ヤングアニマルコミックス)
読了日:03月29日 著者:後藤羽矢子
うわばみ彼女 5 (ヤングアニマルコミックス)
読了日:03月29日 著者:後藤羽矢子
上野さんは不器用 6 (ヤングアニマルコミックス)
読了日:03月29日 著者:tugeneko
変女~変な女子高生 甘栗千子~ 12 (ヤングアニマルコミックス)
読了日:03月30日 著者:此ノ木よしる
読書メーター
2月に読んだ本やマンガ
2月の読書メーター
読んだ本の数:15
読んだページ数:2699
ナイス数:0
法華経 2018年4月 (100分 de 名著)
読了日:02月03日 著者:
エイジ’87 1 (1巻) (ヤングキングコミックス)
読了日:02月03日 著者:上山 道郎
武の心 (文春文庫)
読了日:02月07日 著者:津本 陽
甘々と稲妻(12) (アフタヌーンKC)
読了日:02月07日 著者:雨隠 ギド
バキ外伝 疵面-スカーフェイス-(8) (チャンピオンREDコミックス)
読了日:02月08日 著者:板垣恵介,山内雪奈生
フェイト/エクストラ CCC (4) (角川コミックス・エース)
読了日:02月12日 著者:ろび~な
海と陸をつなぐ進化論 気候変動と微生物がもたらした驚きの共進化 (ブルーバックス)
読了日:02月15日 著者:須藤 斎
はぐれアイドル地獄変 (8) (ニチブンコミックス)
読了日:02月19日 著者:高遠 るい
ベタープログラマ ―優れたプログラマになるための38の考え方とテクニック
読了日:02月19日 著者:Pete Goodliffe
3×3EYES 鬼籍の闇の契約者(4) (ヤンマガKCスペシャル)
読了日:02月21日 著者:高田 裕三
入門 監視 ―モダンなモニタリングのためのデザインパターン
読了日:02月22日 著者:Mike Julian
NHK「100分de名著」ブックス道元 正法眼蔵―わからないことがわかるということが悟り
読了日:02月23日 著者:ひろ さちや
オーバーロード (11) (角川コミックス・エース)
読了日:02月26日 著者:深山 フギン,大塩 哲史
オーバーロード 不死者のOh! (4) (角川コミックス・エース)
読了日:02月26日 著者:じゅうあみ
NHK「100分de名著」ブックス 荘子
読了日:02月26日 著者:玄侑 宗久
読書メーター
RubyのRefinementでモジュールincludeやalias定義はどうなるか
確認してみた結果、refine
でinclude
したモジュールのメソッドや定義したエイリアスは、refinementをusing
したときだけ有効になった。
refine
でinclude
したモジュールはusing
しても見えないがメソッドは有効になるようだ。
確認コード:
module IncludeMethod def include_method :include end end module RefineMethod refine Object do include IncludeMethod def refine_method :refine end alias refine_method_alias refine_method end end p Object.include? IncludeMethod begin refine_method rescue p $! end begin refine_method_alias rescue p $! end begin include_method rescue p $! end using RefineMethod p Object.include? IncludeMethod p refine_method p refine_method_alias p include_method
確認結果:
$ ruby ex_refine.rb false #<NameError: undefined local variable or method `refine_method' for main:Object Did you mean? define_method> #<NameError: undefined local variable or method `refine_method_alias' for main:Object Did you mean? define_method> #<NameError: undefined local variable or method `include_method' for main:Object> false :refine :refine :include
Emacs-Lispのリスト用関数
よく知られたmapcar
以外にもリスト操作のための関数がないか探したら、seq-
系の関数が該当するようだ。
(seq-elt sequence index) (seq-length sequence) (seqp sequence) (seq-drop sequence n) (seq-take sequence n) (seq-take-while predicate sequence) (seq-drop-while predicate sequence) (seq-do function sequence) (seq-map function sequence) (seq-map-indexed function sequence) (seq-mapn function &rest sequences) (seq-remove predicate sequence) (seq-reduce function sequence initial-value) (seq-some predicate sequence) (seq-find predicate sequence &optional default) (seq-every-p predicate sequence) (seq-empty-p sequence) (seq-count predicate sequence) (seq-sort function sequence) (seq-sort-by function predicate sequence) (seq-set-equal-p sequence1 sequence2 &optional testfn) (seq-position sequence elt &optional function) (seq-uniq sequence &optional function) (seq-subseq sequence start &optional end) (seq-concatenate type &rest sequences) (seq-mapcat function sequence &optional type) (seq-partition sequence n) (seq-intersection sequence1 sequence2 &optional function) (seq-difference sequence1 sequence2 &optional function) (seq-group-by function sequence) (seq-into sequence type) (seq-min sequence) (seq-max sequence) (seq-doseq (var sequence) body...) (seq-let arguments sequence body...) (seq-random-elt sequence)
たいていのことは出来そうだ。