@@ -234,11 +234,9 @@ def _releaseLock():
234234 def _register_at_fork_reinit_lock (instance ):
235235 pass # no-op when os.register_at_fork does not exist.
236236else :
237- # A collection of instances with a createLock method (logging.Handler)
237+ # A collection of instances with a _at_fork_reinit method (logging.Handler)
238238 # to be called in the child after forking. The weakref avoids us keeping
239- # discarded Handler instances alive. A set is used to avoid accumulating
240- # duplicate registrations as createLock() is responsible for registering
241- # a new Handler instance with this set in the first place.
239+ # discarded Handler instances alive.
242240 _at_fork_reinit_lock_weakset = weakref .WeakSet ()
243241
244242 def _register_at_fork_reinit_lock (instance ):
@@ -249,16 +247,12 @@ def _register_at_fork_reinit_lock(instance):
249247 _releaseLock ()
250248
251249 def _after_at_fork_child_reinit_locks ():
252- # _acquireLock() was called in the parent before forking.
253250 for handler in _at_fork_reinit_lock_weakset :
254- try :
255- handler .createLock ()
256- except Exception as err :
257- # Similar to what PyErr_WriteUnraisable does.
258- print ("Ignoring exception from logging atfork" , instance ,
259- "._reinit_lock() method:" , err , file = sys .stderr )
260- _releaseLock () # Acquired by os.register_at_fork(before=.
251+ handler ._at_fork_reinit ()
261252
253+ # _acquireLock() was called in the parent before forking.
254+ # The lock is reinitialized to unlocked state.
255+ _lock ._at_fork_reinit ()
262256
263257 os .register_at_fork (before = _acquireLock ,
264258 after_in_child = _after_at_fork_child_reinit_locks ,
@@ -891,6 +885,9 @@ def createLock(self):
891885 self .lock = threading .RLock ()
892886 _register_at_fork_reinit_lock (self )
893887
888+ def _at_fork_reinit (self ):
889+ self .lock ._at_fork_reinit ()
890+
894891 def acquire (self ):
895892 """
896893 Acquire the I/O thread lock.
@@ -2168,6 +2165,9 @@ def emit(self, record):
21682165 def createLock (self ):
21692166 self .lock = None
21702167
2168+ def _at_fork_reinit (self ):
2169+ pass
2170+
21712171# Warnings integration
21722172
21732173_warnings_showwarning = None
0 commit comments