Commit 2bfdbf2 1 parent e88db68 commit 2bfdbf2 Copy full SHA for 2bfdbf2
File tree 2 files changed +5
-18
lines changed
2 files changed +5
-18
lines changed Original file line number Diff line number Diff line change 1
- import atexit
2
1
import os
2
+ import weakref
3
3
from typing import List , Optional
4
4
5
5
import msgspec
@@ -165,15 +165,9 @@ def __init__(
165
165
ready_path = ready_path , # type: ignore[misc]
166
166
** kwargs ,
167
167
)
168
- atexit . register ( self .shutdown )
168
+ self . _finalizer = weakref . finalize ( self , self .shutdown )
169
169
170
170
def shutdown (self ):
171
- # During final garbage collection in process shutdown, atexit may be
172
- # None.
173
- if atexit :
174
- # in case shutdown gets called via __del__ first
175
- atexit .unregister (self .shutdown )
176
-
177
171
# Shut down the zmq context.
178
172
self .ctx .destroy (linger = 0 )
179
173
@@ -197,9 +191,6 @@ def shutdown(self):
197
191
os .remove (socket_file )
198
192
self .proc_handle = None
199
193
200
- def __del__ (self ):
201
- self .shutdown ()
202
-
203
194
204
195
class SyncMPClient (MPClient ):
205
196
"""Synchronous client for multi-proc EngineCore."""
Original file line number Diff line number Diff line change 1
- import atexit
2
1
import os
3
2
import pickle
4
3
import signal
5
4
import sys
6
5
import time
6
+ import weakref
7
7
from dataclasses import dataclass
8
8
from enum import Enum , auto
9
9
from multiprocessing .process import BaseProcess
@@ -37,7 +37,7 @@ class MultiprocExecutor(Executor):
37
37
def __init__ (self , vllm_config : VllmConfig ) -> None :
38
38
# Call self.shutdown at exit to clean up
39
39
# and ensure workers will be terminated.
40
- atexit . register ( self .shutdown )
40
+ self . _finalizer = weakref . finalize ( self , self .shutdown )
41
41
42
42
self .vllm_config = vllm_config
43
43
self .parallel_config = vllm_config .parallel_config
@@ -195,14 +195,10 @@ def _cleanup_sockets(self):
195
195
os .remove (socket_path )
196
196
197
197
def shutdown (self ):
198
- if atexit :
199
- # in case shutdown was called explicitly, we don't need to call it
200
- # again
201
- atexit .unregister (self .shutdown )
202
198
"""Properly shut down the executor and its workers"""
203
199
if getattr (self , 'shutting_down' , False ):
204
200
self .shutting_down = True
205
- for w in self .workers : #TODO: not sure if needed
201
+ for w in self .workers :
206
202
w .worker_response_mq = None
207
203
self ._ensure_worker_termination ()
208
204
You can’t perform that action at this time.
0 commit comments