Skip to content

Commit 6b85a47

Browse files
authored
Automatically clean thread and loop on fork (#1790)
1 parent d1aaebf commit 6b85a47

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: fsspec/asyn.py

+12
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ def get_loop():
151151
return loop[0]
152152

153153

154+
def reset_after_fork():
155+
global lock
156+
loop[0] = None
157+
iothread[0] = None
158+
lock = None
159+
160+
161+
if hasattr(os, "register_at_fork"):
162+
# should be posix; this will do nothing for spawn or forkserver subprocesses
163+
os.register_at_fork(after_in_child=reset_after_fork)
164+
165+
154166
if TYPE_CHECKING:
155167
import resource
156168

0 commit comments

Comments
 (0)