Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PyQではじめるPython

 PyQではじめるPython

519c71549708fd89c02c3aca573acfde?s=128

Shuhei Ozawa

January 15, 2018
Tweet

Transcript

  1. PyQͰ͸͡ΊΔPython Pythonೖ໳ऀͷू͍ #6 2018/01/16 - Ozawa Shuhei ( @oza_shu )

    1
  2. ࣗݾ঺հ — খ୔पฏ — @oza_shu — MSPۀք WEBαʔϏεͷαʔόӡ༻ Pythonೖ໳ऀͷू͍ #6

    2018/01/16 - Ozawa Shuhei ( @oza_shu ) 2
  3. PyQͱ͸ — ࣸܦϕʔεͰ՝୊Λղ͍֮ͯ͑Δ — աڈͷ՝୊Ͱशͬͨจ๏΋൓෮ֶͯ͠शͰ͖Δ — ֶशΧϨϯμʔ͕Ͱ͖ͨ Pythonೖ໳ऀͷू͍ #6 2018/01/16

    - Ozawa Shuhei ( @oza_shu ) 3
  4. ֶशͰ͖Δ಺༰ — جຊతͳจ๏ — WebΞϓϦ(Django) — σʔλॲཧ(pandas) — ػցֶश Pythonೖ໳ऀͷू͍

    #6 2018/01/16 - Ozawa Shuhei ( @oza_shu ) 4
  5. PythonͰLinuxαʔόͱ஥ྑ͘ͳΔ — ΞϓϦΛಈ͔͍ͯ͠Δϓϩηεʹ͍ͭͯ΋ͬͱ஌Γ͍ͨ — Ͳ͏΍ͬͯΞϓϦʹΞΫηε͍ͯ͠Δͷ͔஌Γ͍ͨ Pythonೖ໳ऀͷू͍ #6 2018/01/16 - Ozawa

    Shuhei ( @oza_shu ) 5
  6. ΞϓϦΛಈ͔͍ͯ͠Δϓϩηεʹ͍ͭͯ΋ͬͱ஌Γ͍ͨ — OS͸ϓϩηεΛɺϓϩηεʹׂΓৼΒΕͨPIDΛΈͯ਺஋ ͱͯ͠ѻ͏ — ϓϩηε͕։͍ͨϑΝΠϧʹ͸ϑΝΠϧσΟεΫϦϓλׂ͕ Γ౰ͯΒΕΔ Pythonೖ໳ऀͷू͍ #6 2018/01/16

    - Ozawa Shuhei ( @oza_shu ) 6
  7. ίʔυྫ(1) PIDΛΈͯΈΑ͏ # ݱࡏͷϓϩηεΛฦ͢ import os print ("My pid:", os.getpid())

    $ python3 3_processes_have_pid.py My pid: 10592 Pythonೖ໳ऀͷू͍ #6 2018/01/16 - Ozawa Shuhei ( @oza_shu ) 7
  8. psίϚϯυͰ΋֬ೝͰ͖Δ ps aux |grep zsh USER PID %CPU %MEM VSZ

    RSS TT STAT STARTED TIME COMMAND root 74749 0.0 0.0 4296948 3016 s005 Ss 2:39AM 0:00.11 -zsh root 73439 0.0 0.0 4296948 3028 s003 Ss 2:19AM 0:00.11 -zsh root 63923 0.0 0.0 4296948 2980 s001 Ss+ 11:15PM 0:00.10 -zsh PID͔ΒSWAP࢖༻ྔ͕ଟ͍ϓϩηεΛಛఆ $ grep VmSwap /proc/*/status |sort -k2 -r |head -n /proc/2121/status:VmSwap: 158284 kB /proc/16520/status:VmSwap: 154516 kB /proc/18192/status:VmSwap: 141116 kB Pythonೖ໳ऀͷू͍ #6 2018/01/16 - Ozawa Shuhei ( @oza_shu ) 8
  9. ίʔυྫ(2) ϑΝΠϧσΟεΫϦϓλ # ϑΝΠϧσΟεΫϦϓλׂ͕Γ౰ͯΒΕ͍ͯΔ͔ΈͯΈΑ͏ if __name__ == "__main__": with open("/etc/passwd")

    as passwd: print(passwd.fileno()) # ϑΝΠϧΛด͡Δͱফ͑Δ $ python3 file_descriptors.py 3 Pythonೖ໳ऀͷू͍ #6 2018/01/16 - Ozawa Shuhei ( @oza_shu ) 9
  10. ಛผͳϑΝΠϧσΟεΫϦϓλ — ඪ४ೖྗ → 0 — ඪ४ग़ྗ → 1 —

    ඪ४Τϥʔग़ྗ → 2 >>> sys.stdin.fileno() 0 >>> sys.stdout.fileno() 1 >>> sys.stderr.fileno() 2 Pythonೖ໳ऀͷू͍ #6 2018/01/16 - Ozawa Shuhei ( @oza_shu ) 10
  11. ᐆດͩͬͨॻ͖ํΛཧղͰ͖ΔΑ͏ʹͳͬͨ ! command >/dev/null 2>&1 ! command 2>&1 >/dev/null Pythonೖ໳ऀͷू͍

    #6 2018/01/16 - Ozawa Shuhei ( @oza_shu ) 11
  12. fork()ؾʹͳͬͯ͘Δ ϓϩηε͕Fork͞ΕΔͬͯͲ͏͍͏͜ͱ͚ͩͬ? ࢠϓϩηε͸਌ϓϩηεͰ࢖ΘΕ͍ͯΔશͯͷϝϞϦͷίϐʔΛҾ͖ܧ͙ ϑΝΠϧσΟεΫϦϓλ(ιέοτ)΋ — socket,osϞδϡʔϧͳͲͰpreforkαʔό΋ॻ͚Δ — ίϐʔɾΦϯɾϥΠτʢCoWɺCopy on Writeʣ

    — ԿͰκϯϏϓϩηεͬͯͳΔΜ͚ͩͬ — ϓϩηεؒ௨৴ — ύΠϓॲཧ,ετϦʔϜ,ϝοηʔδ — γάφϧॲཧ — ϓϩηεάϧʔϓ,ηογϣϯάϧʔϓ Pythonೖ໳ऀͷू͍ #6 2018/01/16 - Ozawa Shuhei ( @oza_shu ) 12
  13. ·ͱΊ — PyQ͸ࣸܦΛ௨ͯ͠ͷֶशͳͷͰɺϓϩάϥϛϯάॳΊͨ͹ ͔ΓͷਓʹΑͦ͞͏ — PythonΛ௨ͯ͡Linuxͱ஥ྑ͘ͳΕΔ — ϓϩηε͕Ͳ͏࣮ߦ͞Ε͍ͯΔͷ͔ͪΌΜͱཧղ͢Δॿ͚ ʹ΋ͳΔ Pythonೖ໳ऀͷू͍

    #6 2018/01/16 - Ozawa Shuhei ( @oza_shu ) 13