Skip to content

Instantly share code, notes, and snippets.

@qqpann
Last active August 31, 2018 05:53
Show Gist options
  • Save qqpann/41135b2ace76f1c65f21a7858024be5d to your computer and use it in GitHub Desktop.
Save qqpann/41135b2ace76f1c65f21a7858024be5d to your computer and use it in GitHub Desktop.
[Python Threading] Threading patterns. #threading #python
def f1():
    print('play_wav')
    play_wav(fn)

def f2():
    print('post_to_rpi_api')
    post_to_rpi_api(signals)

# executor = concurrent.futures.ThreadPoolExecutor(max_workers=2)
# executor.submit(f1)
# executor.submit(f3)
# executor.submit(f2)
th1 = threading.Thread(target=f1)
th2 = threading.Thread(target=f2)
th1.start()
th2.start()

https://github.com/SenriYoshikawa/SoapBubble/blob/master/raspberrypi/web_client.py

        thread = threading.Thread(target=self.run, args=())
        thread.daemon = True                            # Daemonize thread
        thread.start()                                  # Start the execution

http://sebastiandahlgren.se/2014/06/27/running-a-method-as-a-background-thread-in-python/

一行で書ける

def hello():
	print('hello')
Thread(target=hello, daemon=True).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment