タグ

ブックマーク / qiita.com/castaneai (2)

  • Pythonの並列・並行処理サンプルコードまとめ - Qiita

    Pythonで同時に2つ以上の処理をする方法を紹介します スレッド スレッドプール プロセスプール イベントループ(コルーチン) スレッド (threading) スレッドを使えば、複数の関数を同時に動かすことができます。 threading.Thread クラスに target として関数を渡し、start() で開始すると動きます。 import time import threading def func1(): while True: print("func1") time.sleep(1) def func2(): while True: print("func2") time.sleep(1) if __name__ == "__main__": thread_1 = threading.Thread(target=func1) thread_2 = threading.Thr

    Pythonの並列・並行処理サンプルコードまとめ - Qiita
    takuwz
    takuwz 2019/11/29
  • Go言語でシンプルに構造体⇔バイナリの相互変換 - Qiita

    構造体をサクッとバイナリに変換したい! そんなときはencoding/binaryパッケージを使います。 構造体→バイナリ binary.Writeメソッドに構造体を渡すと上から順番にフィールドが並んだバイナリになります。 package main import ( "encoding/binary" "encoding/hex" "os" ) type A struct { Int32Field int32 ByteField byte } func main() { // 構造体つくる a := A{Int32Field: 0x123456, ByteField: 0xFF} stdoutDumper := hex.Dumper(os.Stdout) defer stdoutDumper.Close() // 構造体をバイナリにする binary.Write(stdoutDumper,

    Go言語でシンプルに構造体⇔バイナリの相互変換 - Qiita
    takuwz
    takuwz 2018/12/28
  • 1