multithreading - Can I run multiple threads in a single heroku (python) dyno? -


does threading module work when running single dyno on heroku? eg:

import threading import time import random   def foo(x, s):         time.sleep(s)     print ("%s %s %s" % (threading.current_thread(), x, s))  x in range(4):     threading.thread(target=foo, args=(x, random.random())).start() 

should return like...

$ python3 mythread.py <thread(thread-3, started 123145318068224)> 2 0.27166873449907303 <thread(thread-4, started 123145323323392)> 3 0.5510182055055494 <thread(thread-1, started 123145307557888)> 0 0.642366815814484 <thread(thread-2, started 123145312813056)> 1 0.8985126103340428 

does it?

yes. works fine =) tested on latest python 3 release. can test on heroku yourself.

heroku dynos using virtual cpu cores, threading still works fine.

edit: here's heroku logs

2016-08-02t20:18:35.040230+00:00 heroku[test.1]: state changed starting 2016-08-02t20:18:36.871061+00:00 app[test.1]: <thread(thread-3, started 140472762279680)> 2 0.10491314677740204 2016-08-02t20:18:36.969173+00:00 app[test.1]: <thread(thread-1, started 140472795842304)> 0 0.2034461123977389 2016-08-02t20:18:37.117934+00:00 app[test.1]: <thread(thread-2, started 140472779060992)> 1 0.35186381754517004 2016-08-02t20:18:37.476239+00:00 app[test.1]: <thread(thread-4, started 140472542557952)> 3 0.7093646481085698 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -