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

Can ray.util.queue.Empty extend queue.Empty? #50154

Closed
rsamf opened this issue Jan 31, 2025 · 4 comments · Fixed by #50261
Closed

Can ray.util.queue.Empty extend queue.Empty? #50154

rsamf opened this issue Jan 31, 2025 · 4 comments · Fixed by #50261
Assignees
Labels
core Issues that should be addressed in Ray Core enhancement Request for new feature and/or capability good-first-issue Great starter issue for someone just starting to contribute to Ray jira-core P2 Important issue, but not time-critical

Comments

@rsamf
Copy link

rsamf commented Jan 31, 2025

Description

I am trying to catch Empty queue exceptions where my queue can either be a multiprocess queue or ray.util.queue. Currently, I have to do this:

...
except queue.Empty:
    pass
except ray.util.queue.Empty:
    pass

because ray.util.queue.Empty is not a subclass of Python's built-in queue.Empty but rather Python's built-in Exception class. See:

class Empty(Exception):

A quick fix would be to just change it to extend queue.Empty, and while at it, also change Full to extend queue.Full too?

I think this would be a good first issue. Thanks!

Use case

Code conciseness for Ray users

@rsamf rsamf added enhancement Request for new feature and/or capability triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Jan 31, 2025
@wingkitlee0
Copy link
Contributor

wingkitlee0 commented Jan 31, 2025

Python allows you to catch multiple exceptions like

    ...
except (queue.Empty, ray.util.queue.Empty) as e:
    ...

See https://docs.python.org/3/tutorial/errors.html#handling-exceptions
Does it help?

Also, Ray's Queue is not a subclass of Python's Queue.. so it may cause confusion with the suggestion above

@rsamf
Copy link
Author

rsamf commented Jan 31, 2025

@wingkitlee0 Right, I'm aware, but I run into the same problem.

Also, Ray's Queue is not a subclass of Python's Queue.. so it may cause confusion with the suggestion above

Python has an implementation of a simple queue: queue.SimpleQueue which doesn't implement queue.Queue but raises queue.Empty, queue.Full, and queue.ShutDown. These are exceptions that aren't for queue.Queue classes but shareable for any queue in Python in my opinion.

@wingkitlee0
Copy link
Contributor

the same problem.

do you mind elaborate?

SimpleQueue ... raises queue.Empty, queue.Full

that's fair. Indeed, multiprocessing.Queue also raises them directly. So maybe Ray should raise them directly as well (without subclass).

@rsamf
Copy link
Author

rsamf commented Feb 1, 2025

except (queue.Empty, ray.util.queue.Empty):
  ...

Is syntactic sugar for

except queue.Empty:
    ...
except ray.util.queue.Empty:
    ...

I would prefer to do

except queue.Empty:
  ...

in my case.

Raising queue.Empty and queue.Full directly would be even better.

@jcotant1 jcotant1 added the core Issues that should be addressed in Ray Core label Feb 2, 2025
@jjyao jjyao added good-first-issue Great starter issue for someone just starting to contribute to Ray P2 Important issue, but not time-critical and removed triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Feb 3, 2025
@israbbani israbbani self-assigned this Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues that should be addressed in Ray Core enhancement Request for new feature and/or capability good-first-issue Great starter issue for someone just starting to contribute to Ray jira-core P2 Important issue, but not time-critical
Projects
None yet
5 participants