Created
November 23, 2019 20:10
-
-
Save diverru/3b317313366311fc260707cc91e77994 to your computer and use it in GitHub Desktop.
promise fuckups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from promise import Promise | |
from threading import Thread | |
import threading | |
import time | |
import functools | |
def on_resolve(issued_by, fn): | |
name = threading.current_thread().getName() | |
if issued_by != name: | |
print(issued_by, name) | |
def worker(): | |
my_name = threading.current_thread().getName() | |
now = time.time() | |
while now + 5 > time.time(): | |
promise = Promise.resolve(None) | |
promise.then(functools.partial(on_resolve, my_name)) | |
#time.sleep(0.001) | |
threads = [] | |
for i in range(3): | |
threads.append(Thread(target=worker)) | |
for thread in threads: | |
thread.start() | |
for thread in threads: | |
thread.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment