@@ -38,7 +38,7 @@ def update_pid_file(cls):
38
38
pass
39
39
40
40
@classmethod
41
- def register_instance (cls , unique_worker_id = None , worker_name = None , api_client = None ):
41
+ def register_instance (cls , unique_worker_id = None , worker_name = None , api_client = None , allow_double = False ):
42
42
"""
43
43
# Exit the process if another instance of us is using the same worker_id
44
44
@@ -65,8 +65,9 @@ def register_instance(cls, unique_worker_id=None, worker_name=None, api_client=N
65
65
f .write (bytes (os .getpid ()))
66
66
f .flush ()
67
67
try :
68
- ret = cls ._register_instance (unique_worker_id = unique_worker_id , worker_name = worker_name ,
69
- api_client = api_client )
68
+ ret = cls ._register_instance (
69
+ unique_worker_id = unique_worker_id , worker_name = worker_name ,
70
+ api_client = api_client , allow_double = allow_double )
70
71
except :
71
72
ret = None , None
72
73
@@ -78,7 +79,7 @@ def register_instance(cls, unique_worker_id=None, worker_name=None, api_client=N
78
79
return ret
79
80
80
81
@classmethod
81
- def _register_instance (cls , unique_worker_id = None , worker_name = None , api_client = None ):
82
+ def _register_instance (cls , unique_worker_id = None , worker_name = None , api_client = None , allow_double = False ):
82
83
if cls .worker_id :
83
84
return cls .worker_id , cls .instance_slot
84
85
# make sure we have a unique name
@@ -123,7 +124,11 @@ def _register_instance(cls, unique_worker_id=None, worker_name=None, api_client=
123
124
continue
124
125
125
126
if uid == unique_worker_id :
126
- return None , None
127
+ if allow_double :
128
+ warning ('Instance with the same WORKER_ID [{}] was found on this machine. '
129
+ 'We are ignoring it, make sure this not a mistake.' .format (unique_worker_id ))
130
+ else :
131
+ return None , None
127
132
128
133
slots [slot ] = uid
129
134
0 commit comments