Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deferred promise does not handle reject #50

Open
DmitryPorotov opened this issue Jan 15, 2018 · 0 comments
Open

Deferred promise does not handle reject #50

DmitryPorotov opened this issue Jan 15, 2018 · 0 comments

Comments

@DmitryPorotov
Copy link

This is my code:

from promise import Promise
from threading import Timer
from time import sleep


class MyClass:
    def __init__(self):
	self.p = None

    def get_promise(self):
	self.p = Promise()

	def reject():
	    self.p.reject(Exception("qwe"))

	def resolve():
	    self.p.fulfill("asd")

	Timer(3, reject).start()
	return self.p


i = MyClass()


def on_resolve(x):
    print(str(x))


def on_reject(x):
    print(str(x))


p = i.get_promise()
p.then(on_resolve, on_reject)

while 1:
    sleep(1)

on_reject is never called in the master branch version (2.1.0). But it works fine in 1.0.1.
I've stepped through execution and I think I might have found the problem. I saw that the code goes to this function:

def _reject(self, reason, traceback=None):
    self._state = STATE_REJECTED
    self._fulfillment_handler0 = reason
    self._traceback = traceback

    if self._is_final:
        assert self._length == 0
        return async_instance.fatal_error(reason)

    if self._length > 0:
        async_instance.settle_promises(self)
    else:
        self._ensure_possible_rejection_handled()  # the execution goes here

    if self._is_async_guaranteed:
        self._settle_promises()
    else:
        async_instance.settle_promises(self)

But _ensure_possible_rejection_handled does nothing:

def _ensure_possible_rejection_handled(self):
    # self._rejection_is_unhandled = True
    # async_instance.invoke_later(self._notify_unhandled_rejection, self)
    pass

Is it a bug or am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant