@@ -60,6 +60,19 @@ def create_pipe_event(
60
60
return _pipe_event
61
61
62
62
63
+ def run_direction (from_bot : Dict [str , Any ], to_bot : Dict [str , Any ], stream_wide : bool ) -> None :
64
+ """
65
+ Child-process entrypoint. Each child constructs its own clients so no Session
66
+ objects are ever inherited or pickled.
67
+ """
68
+ from_client = zulip .Client (
69
+ email = from_bot ["email" ], api_key = from_bot ["api_key" ], site = from_bot ["site" ]
70
+ )
71
+ to_client = zulip .Client (email = to_bot ["email" ], api_key = to_bot ["api_key" ], site = to_bot ["site" ])
72
+ pipe_event = create_pipe_event (to_client , from_bot , to_bot , stream_wide )
73
+ from_client .call_on_each_event (pipe_event , ["message" ])
74
+
75
+
63
76
if __name__ == "__main__" :
64
77
usage = """run-interrealm-bridge [--stream]
65
78
@@ -78,16 +91,12 @@ if __name__ == "__main__":
78
91
args = parser .parse_args ()
79
92
80
93
options = interrealm_bridge_config .config
81
-
82
94
bot1 = options ["bot_1" ]
83
95
bot2 = options ["bot_2" ]
84
- client1 = zulip .Client (email = bot1 ["email" ], api_key = bot1 ["api_key" ], site = bot1 ["site" ])
85
- client2 = zulip .Client (email = bot2 ["email" ], api_key = bot2 ["api_key" ], site = bot2 ["site" ])
86
- # A bidirectional tunnel
87
- pipe_event1 = create_pipe_event (client2 , bot1 , bot2 , args .stream )
88
- p1 = mp .Process (target = client1 .call_on_each_event , args = (pipe_event1 , ["message" ]))
89
- pipe_event2 = create_pipe_event (client1 , bot2 , bot1 , args .stream )
90
- p2 = mp .Process (target = client2 .call_on_each_event , args = (pipe_event2 , ["message" ]))
96
+
97
+ ctx = mp .get_context ("spawn" )
98
+ p1 = ctx .Process (target = run_direction , args = (bot1 , bot2 , args .stream ))
99
+ p2 = ctx .Process (target = run_direction , args = (bot2 , bot1 , args .stream ))
91
100
p1 .start ()
92
101
p2 .start ()
93
102
print ("Listening..." )
0 commit comments