@@ -112,11 +112,29 @@ class Manager:
112
112
same process as the manager.
113
113
`duration` : float
114
114
The duration to run the manager for. If `0`, runs indefinitely.
115
+ `communication_backend` : str
116
+ The communication backend to use for node communication. Default is "mp" (multiprocessing).
115
117
"""
116
118
117
119
def __init__ (
118
- self , filepath : Optional [str ] = None , headless : bool = True , use_multiprocessing : bool = True , duration : float = 0
120
+ self ,
121
+ filepath : Optional [str ] = None ,
122
+ headless : bool = True ,
123
+ use_multiprocessing : bool = True ,
124
+ duration : float = 0 ,
125
+ communication_backend : str = "mp" ,
119
126
) -> None :
127
+ # create a multiprocessing manager
128
+ self ._mp_manager = MPManager ()
129
+
130
+ try :
131
+ # set up communication backend
132
+ Connection .set_backend (communication_backend , self ._mp_manager )
133
+ except AssertionError :
134
+ print ("Connection backend already set. Skipping." )
135
+ # make sure the connection backend is set correctly
136
+ assert Connection ._BACKEND == communication_backend
137
+
120
138
# TODO: add proper logging
121
139
print ("Starting goofi-pipe..." )
122
140
# preload all nodes to avoid delays
@@ -319,7 +337,9 @@ def remove_node(self, name: str, notify_gui: bool = True, **gui_kwargs) -> None:
319
337
Window ().remove_node (name , ** gui_kwargs )
320
338
321
339
@mark_unsaved_changes
322
- def add_link (self , node_out : str , node_in : str , slot_out : str , slot_in : str , notify_gui : bool = True , ** gui_kwargs ) -> None :
340
+ def add_link (
341
+ self , node_out : str , node_in : str , slot_out : str , slot_in : str , notify_gui : bool = True , ** gui_kwargs
342
+ ) -> None :
323
343
"""
324
344
Adds a link between two nodes.
325
345
@@ -403,6 +423,9 @@ def terminate(self, notify_gui: bool = True) -> None:
403
423
for node in self .nodes :
404
424
self .nodes [node ].terminate ()
405
425
426
+ # close the communication backend
427
+ self ._mp_manager .shutdown ()
428
+
406
429
def save (self , filepath : Optional [str ] = None , overwrite : bool = False , timeout : float = 3.0 ) -> None :
407
430
"""
408
431
Saves the state of the manager to a file.
@@ -585,21 +608,14 @@ def main(duration: float = 0, args=None):
585
608
docs ()
586
609
return
587
610
588
- with MPManager () as manager :
589
- # set the communication backend
590
- try :
591
- Connection .set_backend (args .comm , manager )
592
- except AssertionError :
593
- # connection backend is already set (occurrs when running tests)
594
- pass
595
-
596
- # create and run the manager (this blocks until the manager is terminated)
597
- Manager (
598
- filepath = args .filepath ,
599
- headless = args .headless ,
600
- use_multiprocessing = not args .no_multiprocessing ,
601
- duration = duration ,
602
- )
611
+ # create and run the manager (this blocks until the manager is terminated)
612
+ Manager (
613
+ filepath = args .filepath ,
614
+ headless = args .headless ,
615
+ use_multiprocessing = not args .no_multiprocessing ,
616
+ duration = duration ,
617
+ communication_backend = args .comm ,
618
+ )
603
619
604
620
605
621
def docs ():
0 commit comments