File tree Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -1420,7 +1420,7 @@ def _get_socket(self):
1420
1420
# See test.test_client:TestClient.test_fork for an example of
1421
1421
# what could go wrong otherwise
1422
1422
if self .pid != os .getpid ():
1423
- self .reset ()
1423
+ self .reset_without_pause ()
1424
1424
1425
1425
if self .closed :
1426
1426
if self .enabled_for_cmap :
@@ -1526,7 +1526,7 @@ def return_socket(self, sock_info):
1526
1526
if self .enabled_for_cmap :
1527
1527
listeners .publish_connection_checked_in (self .address , sock_info .id )
1528
1528
if self .pid != os .getpid ():
1529
- self .reset ()
1529
+ self .reset_without_pause ()
1530
1530
else :
1531
1531
if self .closed :
1532
1532
sock_info .close_socket (ConnectionClosedReason .POOL_CLOSED )
Original file line number Diff line number Diff line change @@ -169,20 +169,24 @@ def open(self):
169
169
forking.
170
170
171
171
"""
172
+ pid = os .getpid ()
172
173
if self ._pid is None :
173
- self ._pid = os .getpid ()
174
- else :
175
- if os .getpid () != self ._pid :
176
- warnings .warn (
177
- "MongoClient opened before fork. Create MongoClient only "
178
- "after forking. See PyMongo's documentation for details: "
179
- "https://pymongo.readthedocs.io/en/stable/faq.html#"
180
- "is-pymongo-fork-safe"
181
- )
182
- with self ._lock :
183
- # Reset the session pool to avoid duplicate sessions in
184
- # the child process.
185
- self ._session_pool .reset ()
174
+ self ._pid = pid
175
+ elif pid != self ._pid :
176
+ self ._pid = pid
177
+ warnings .warn (
178
+ "MongoClient opened before fork. Create MongoClient only "
179
+ "after forking. See PyMongo's documentation for details: "
180
+ "https://pymongo.readthedocs.io/en/stable/faq.html#"
181
+ "is-pymongo-fork-safe"
182
+ )
183
+ with self ._lock :
184
+ # Close servers and clear the pools.
185
+ for server in self ._servers .values ():
186
+ server .close ()
187
+ # Reset the session pool to avoid duplicate sessions in
188
+ # the child process.
189
+ self ._session_pool .reset ()
186
190
187
191
with self ._lock :
188
192
self ._ensure_opened ()
You can’t perform that action at this time.
0 commit comments