# subprocesses are a huge hassle
# on Linux there is simply no way to async wait for a child to exit except by
# messing with SIGCHLD and that is ... *such* a mess. Not really
# tenable. We're better off trying os.waitpid(..., os.WNOHANG), and if that
# says the process is still going then spawn a thread to sit in waitpid.
# ......though that waitpid is non-cancellable so ugh. this is a problem,
# because it's also mutating -- you only get to waitpid() once, and you have
# to do it, because zombies. I guess we could make sure the waitpid thread is
# daemonic and either it gets back to us eventually (even if our first call to
# 'await wait()' is cancelled, maybe another one won't be), or else we go away
# and don't care anymore.
# I guess simplest is just to spawn a thread at the same time as we spawn the
# process, with more reasonable notification semantics.
# or we can poll every 100 ms or something, sigh.
# on Mac/*BSD then kqueue works, go them. (maybe have WNOHANG after turning it
# on to avoid a race condition I guess)
# on Windows, you can either do the thread thing, or something involving
# WaitForMultipleObjects, or the Job Object API:
# https://stackoverflow.com/questions/17724859/detecting-exit-failure-of-child-processes-using-iocp-c-windows
# (see also the comments here about using the Job Object API:
# https://stackoverflow.com/questions/23434842/python-how-to-kill-child-processes-when-parent-dies/23587108#23587108)
# however the docs say:
# "Note that, with the exception of limits set with the
# JobObjectNotificationLimitInformation information class, delivery of
# messages to the completion port is not guaranteed; failure of a message to
# arrive does not necessarily mean that the event did not occur"
#
# oh windows wtf
# We'll probably want to mess with the job API anyway for worker processes
# (b/c that's the reliable way to make sure we never leave residual worker
# processes around after exiting, see that stackoverflow question again), so
# maybe this isn't too big a hassle? waitpid is probably easiest for the
# first-pass implementation though.
# the handle version has the same issues as waitpid on Linux, except I guess
# that on windows the waitpid equivalent doesn't consume the handle.
# -- wait no, the windows equivalent takes a timeout! and we know our
# cancellation deadline going in, so that's actually okay. (Still need to use
# a thread but whatever.)
# asyncio does RegisterWaitForSingleObject with a callback that does
# PostQueuedCompletionStatus.
# this is just a thread pool in disguise (and in principle could have weird
# problems if you have enough children and run out of threads)
# it's possible we could do something with a thread that just sits in
# an alertable state and handle callbacks...? though hmm, maybe the set of
# events that can notify via callbacks is equivalent to the set that can
# notify via IOCP.
# there's WaitForMultipleObjects to let multiple waits share a thread I
# guess.
# you can wake up a WaitForMultipleObjectsEx on-demand by using QueueUserAPC
# to send a no-op APC to its thread.
# this is also a way to cancel a WaitForSingleObjectEx, actually. So it
# actually is possible to cancel the equivalent of a waitpid on Windows.
# Potentially useful observation: you *can* use a socket as the
# stdin/stdout/stderr for a child, iff you create that socket *without*
# WSA_FLAG_OVERLAPPED:
# http://stackoverflow.com/a/5725609
# Here's ncm's Windows implementation of socketpair, which has a flag to
# control whether one of the sockets has WSA_FLAG_OVERLAPPED set:
# https://github.com/ncm/selectable-socketpair/blob/master/socketpair.c
# (it also uses listen(1) so it's robust against someone intercepting things,
# unlike the version in socket.py... not sure anyone really cares, but
# hey. OTOH it only supports AF_INET, while socket.py supports AF_INET6,
# fancy.)
# (or it would be trivial to (re)implement in python, using either
# socket.socketpair or ncm's version as a model, given a cffi function to
# create the non-overlapped socket in the first place then just pass it into
# the socket.socket constructor (avoiding the dup() that fromfd does).)
没有合适的资源?快使用搜索试试~ 我知道了~
trio-Python异步并发和 IO 的友好库
共268个文件
py:188个
rst:21个
svg:10个
0 下载量 76 浏览量
2024-10-06
20:40:53
上传
评论
收藏 730KB ZIP 举报
温馨提示
trio-Python异步并发和 IO 的友好库
资源推荐
资源详情
资源评论
收起资源包目录
trio-Python异步并发和 IO 的友好库 (268个子文件)
LICENSE.APACHE2 11KB
make.bat 812B
astrill-codesigning-cert.cer 1KB
server.crt 1KB
server.csr 956B
hackrtd.css 3KB
.git-blame-ignore-revs 152B
.gitattributes 180B
.gitignore 795B
.gitkeep 0B
.gitkeep 0B
.gitkeep 0B
layout.html 1KB
test-requirements.in 897B
docs-requirements.in 574B
MANIFEST.in 259B
_check_type_completeness.json 4KB
server.orig.key 2KB
server.key 2KB
LICENSE 190B
Makefile 606B
CONTRIBUTING.md 98B
CODE_OF_CONDUCT.md 98B
LICENSE.MIT 1KB
across-realtime.out 832B
trio-test-1.pem 4KB
trio-test-1.pem 4KB
trio-test-CA.pem 1KB
trio-test-CA.pem 1KB
favicon-32.png 2KB
_run.py 118KB
test_run.py 93KB
_dtls.py 54KB
_subprocess.py 52KB
test_ssl.py 50KB
_ssl.py 45KB
_socket.py 45KB
_io_windows.py 42KB
test_socket.py 41KB
test_threads.py 38KB
test_dtls.py 33KB
_sync.py 30KB
_abc.py 25KB
_threads.py 23KB
test_subprocess.py 23KB
_raises_group.py 23KB
_memory_streams.py 23KB
socket.py 22KB
_check_streams.py 22KB
test_guest_mode.py 22KB
test_highlevel_open_tcp_stream.py 22KB
test_exports.py 20KB
test_testing.py 20KB
_highlevel_open_tcp_stream.py 18KB
_fake_net.py 18KB
_io_epoll.py 17KB
test_sync.py 17KB
_channel.py 16KB
conf.py 16KB
test_ki.py 16KB
test_io.py 16KB
_highlevel_socket.py 15KB
_file_io.py 15KB
_util.py 14KB
test_testing_raisesgroup.py 14KB
_windows_cffi.py 14KB
test_highlevel_open_tcp_listeners.py 13KB
test_channel.py 13KB
gen_exports.py 12KB
_traps.py 12KB
_io_kqueue.py 11KB
test_asyncgen.py 11KB
_thread_cache.py 11KB
test_highlevel_socket.py 11KB
_generated_run.py 10KB
test_windows.py 10KB
test_unix_pipes.py 10KB
_ki.py 10KB
_highlevel_open_tcp_listeners.py 10KB
_asyncgens.py 10KB
check_type_completeness.py 10KB
test_fakenet.py 10KB
raisesgroup.py 10KB
test_util.py 9KB
_parking_lot.py 9KB
_entry_queue.py 9KB
_path.py 9KB
test_timeouts.py 8KB
test_instrumentation.py 8KB
test_wait_for_object.py 8KB
test_deprecate.py 8KB
_unix_pipes.py 8KB
_generated_io_windows.py 8KB
test_path.py 8KB
test_repl.py 8KB
test_file_io.py 8KB
test_signals.py 7KB
_signals.py 7KB
afd-lab.py 6KB
_highlevel_ssl_helpers.py 6KB
共 268 条
- 1
- 2
- 3
资源评论
Unity打怪升级
- 粉丝: 1w+
- 资源: 208
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功