-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
add: wrapper for run
and run_thread
#5
Comments
What's the most common situation I find myself in: Step 1: Create Queues
Step 2: Create Workers Step 3: Put Messages Step 4: Wait (Optional) Step 5: Post-processing |
In many ways this issue is connected to #2 because this wrapper would probably also be a |
What might this wrapper look like: q = ezq.Q()
with ProcessPool(f, q, other_arg, size=3) as workers:
# something Yeah, not loving it. The problem is that you'd have to have the input queue as the first arg by convention and it's a little too magical. |
Meh, I guess I'll live with the long name until I come up with a thing that properly unites the workers with the input queue. |
Heh. I actually thought of a way to add this to #4: have the queue wrapper wait for workers. q.wait(workers) |
Another thing I tried, but discarded: class Worker:
worker: Union[Process, Thread]
def __init__(self, func, *args, thread=False, **kwargs):
if thread:
self.worker = Thread(daemon=True, target=func, args=args, kwargs=kwargs)
else:
self.worker = Process(daemon=True, target=func, args=args, kwargs=kwargs)
self.worker.start()
def __getattr__(self, name: str) -> Any:
return getattr(self.worker, name)
def __enter__(self):
return self
def __exit__(self, *_):
self.worker.join() I may eventually make a wrapper like this, but I don't really see the benefit at the moment. There's not much value beyond the actual |
So now I think the value of this comes from having a level of indirection that is easier to manipulate in the future. Perhaps I should name the class |
I've been debating the name and chose to ask GPT-4. metaist: For this library, I'm thinking of wrapping GPT: Sure, let's explore the pros and cons of each name:
Pros:
Cons:
Pros:
Cons:
In conclusion, the decision should be based on how you want users to perceive the class. If you want to emphasize the entity that does the work, metaist: What are some pros and cons of a name like GPT: Pros:
Cons:
Overall, |
Guess I'll go with |
Given #4, long function names like
endq_and_wait
feel weird.The text was updated successfully, but these errors were encountered: