<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>otiai10</author_name>
  <author_url>https://blog.hatena.ne.jp/otiai10/</author_url>
  <blog_title>DRYな備忘録</blog_title>
  <blog_url>https://otiai10.hatenablog.com/</blog_url>
  <categories>
    <anon>go</anon>
  </categories>
  <description>問題 deferを使って後処理をしたい場合に、プロセスがCtrl+cなどSIGINTで中断されるとdeferしたものが発火しない。プロセス自体が中断されるのであたりまえなんだけども。 問題の再現 package main import ( &quot;fmt&quot; &quot;time&quot; ) func main() { defer teardown() hoge() fmt.Println(&quot;終了&quot;) } func hoge() { for i := 0; i &lt; 5; i++ { fmt.Println(i) time.Sleep(1 * time.Second) } } func teardown() { fmt…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fotiai10.hatenablog.com%2Fentry%2F2018%2F02%2F19%2F165228&quot; title=&quot;【Go言語】Ctrl+cなどによるSIGINTの捕捉とdeferの実行 - DRYな備忘録&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>https://images-fe.ssl-images-amazon.com/images/I/41BaAiMmrnL._SL160_.jpg</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2018-02-19 16:52:28</published>
  <title>【Go言語】Ctrl+cなどによるSIGINTの捕捉とdeferの実行</title>
  <type>rich</type>
  <url>https://otiai10.hatenablog.com/entry/2018/02/19/165228</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
