@@ -28,6 +28,7 @@ def __init__(self, source):
28
28
self .source : BaseSource = source
29
29
30
30
self ._exceptions : List [Exception ] = []
31
+ self ._started = False
31
32
self ._stopping = False
32
33
33
34
# copy parent process log level to the child process
@@ -36,6 +37,10 @@ def __init__(self, source):
36
37
# reader and writer pipe used to communicate from the child to the parent process
37
38
self ._rpipe , self ._wpipe = multiprocessing .Pipe (duplex = False )
38
39
40
+ @property
41
+ def started (self ):
42
+ return self ._started
43
+
39
44
# --- CHILD PROCESS METHODS --- #
40
45
41
46
def _setup_signal_handlers (self ):
@@ -54,6 +59,7 @@ def run(self) -> None:
54
59
* Execution of the source `run` method
55
60
* Reporting the source exceptions to the parent process
56
61
"""
62
+ self ._started = True
57
63
self ._setup_signal_handlers ()
58
64
configure_logging (self ._loglevel , str (self .source ), pid = True )
59
65
logger .info ("Source started" )
@@ -103,6 +109,7 @@ def _report_exception(self, err: BaseException) -> None:
103
109
104
110
def start (self ) -> "SourceProcess" :
105
111
logger .info ("Starting source %s" , self .source )
112
+ self ._started = True
106
113
return super ().start ()
107
114
108
115
def raise_for_error (self ) -> None :
@@ -186,7 +193,8 @@ def topics(self) -> List[Topic]:
186
193
187
194
def start_sources (self ) -> None :
188
195
for process in self .processes :
189
- process .start ()
196
+ if not process .started :
197
+ process .start ()
190
198
191
199
def stop_sources (self ) -> None :
192
200
for process in self .processes :
@@ -221,7 +229,6 @@ def is_alive(self) -> bool:
221
229
return False
222
230
223
231
def __enter__ (self ):
224
- self .start_sources ()
225
232
return self
226
233
227
234
def __exit__ (self , * args , ** kwargs ):
0 commit comments