-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
interrealm: Add option to run the bridge unidirectionally. #459
base: main
Are you sure you want to change the base?
Conversation
Heads up @rht, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
@neiljp can you take a look at this? |
p2.start() | ||
print("Listening...") | ||
p1.join() | ||
p2.join() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do this without duplicating code between the two paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the simplest way to do it without having to add more lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is cleaner to read, but if this is equivalent then you could have:
1 if not args.oneway:
2 pipe_event2 = ...
3 p2 = mp.Process(...)
4 p2.start()
5 p1.start()
6 print("Listening")
7 p1.join()
8 if not args.oneway
9 p2.join()
Does the start()
order matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is possible to do it that way too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this could be achieved more cleanly by using concurrent.futures
?
p2.start() | ||
print("Listening...") | ||
p1.join() | ||
p2.join() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is cleaner to read, but if this is equivalent then you could have:
1 if not args.oneway:
2 pipe_event2 = ...
3 p2 = mp.Process(...)
4 p2.start()
5 p1.start()
6 print("Listening")
7 p1.join()
8 if not args.oneway
9 p2.join()
Does the start()
order matter?
@neiljp how does a |
@rht I haven't explored it in detail for this application, but it could perhaps be something like the following (untested): from concurrent.futures import ProcessPoolExecutor, wait
pipe_event1 = create_pipe_event(client2, bot1, bot2, args.stream)
with ProcessPoolExecutor(max_workers=2) as executor:
f = [executor.submit(client1.call_on_each_event, pipe_event1, ["message"])]
if not args.oneway:
pipe_event2 = create_pipe_event(client1, bot2, bot1, args.stream)
f += [executor.submit(client2.call_on_each_event, pipe_event2, ["message"])]
print("Listening...")
wait(f) I used this module in zulip-terminal recently. |
That looks like a bit longer than I thought ( f1 = executor.submit(client1.call_on_each_event, pipe_event1, ["message"])
f1.future() ? |
Longer? The original is 13 lines, and the new one is 8, plus the import line - plus cleaner, in my opinion, though no guarantee it's directly equivalent as I'm not completely familiar with the existing code. Re your question, Refactoring for the other structures is a separate step, which I hadn't considered. |
"Longer" in a horizontal way rather than vertical way, in terms of the number of nested expressions. Aside: maybe they (anything that runs n functions in parallel) could be wrapped in a run_parallel((func1, args1), (func2, args2), ...) There is a |
The extra level of nesting is due to that context manager, which tidies things up automatically - does the same happen currently? You could get a result by |
Heads up @rht, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
This is for the use case of playground.zulipdev.org.