本文整理汇总了Python中msvcrt.open_osfhandle方法的典型用法代码示例。如果您正苦于以下问题:Python msvcrt.open_osfhandle方法的具体用法?Python msvcrt.open_osfhandle怎么用?Python msvcrt.open_osfhandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msvcrt
的用法示例。
在下文中一共展示了msvcrt.open_osfhandle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _winapi_childhandle_after_createprocess_child
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def _winapi_childhandle_after_createprocess_child(self):
"""Called on Windows in the child process after the CreateProcess()
system call. This is required for making the handle usable in the child.
"""
if WINAPI_HANDLE_TRANSFER_STEAL:
# In this case the handle has not been inherited by the child
# process during CreateProcess(). Steal it from the parent.
new_winapihandle = multiprocessing.reduction.steal_handle(
self._parent_pid, self._parent_winapihandle)
del self._parent_winapihandle
del self._parent_pid
# Restore C file descriptor with (read/write)only flag.
self._fd = msvcrt.open_osfhandle(new_winapihandle, self._fd_flag)
return
# In this case the handle has been inherited by the child process during
# the CreateProcess() system call. Get C file descriptor from Windows
# file handle.
self._fd = msvcrt.open_osfhandle(
self._inheritable_winapihandle, self._fd_flag)
del self._inheritable_winapihandle
示例2: main
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def main():
'''
Run code specified by data received over pipe
'''
assert is_forking(sys.argv)
handle = int(sys.argv[-1])
fd = msvcrt.open_osfhandle(handle, os.O_RDONLY)
from_parent = os.fdopen(fd, 'rb')
process.current_process()._inheriting = True
preparation_data = load(from_parent)
prepare(preparation_data)
self = load(from_parent)
process.current_process()._inheriting = False
from_parent.close()
exitcode = self._bootstrap()
exit(exitcode)
示例3: main
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def main():
'''
Run code specifed by data received over pipe
'''
assert is_forking(sys.argv)
handle = int(sys.argv[-1])
fd = msvcrt.open_osfhandle(handle, os.O_RDONLY)
from_parent = os.fdopen(fd, 'rb')
process.current_process()._inheriting = True
preparation_data = load(from_parent)
prepare(preparation_data)
self = load(from_parent)
process.current_process()._inheriting = False
from_parent.close()
exitcode = self._bootstrap()
exit(exitcode)
示例4: __init__
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def __init__(self, output=sys.stdout):
self._close_output = False
# If output is integer, assume it is file descriptor and open it
if isinstance(output, int):
self._close_output = True
if sys.platform == 'win32':
output = msvcrt.open_osfhandle(output, 0)
output = open(output, 'wb')
# Get underlying buffered file object
try:
self.output = output.buffer
except AttributeError:
self.output = output
# Use only one writer thread to preserve sequence of written frequencies
self._executor = threadpool.ThreadPoolExecutor(
max_workers=1,
max_queue_size=100,
thread_name_prefix='Writer_thread'
)
示例5: spawn_main
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def spawn_main(pipe_handle, parent_pid=None, tracker_fd=None):
'''
Run code specifed by data received over pipe
'''
assert is_forking(sys.argv)
if sys.platform == 'win32':
import msvcrt
from .reduction import steal_handle
new_handle = steal_handle(parent_pid, pipe_handle)
fd = msvcrt.open_osfhandle(new_handle, os.O_RDONLY)
else:
from . import semaphore_tracker
semaphore_tracker._semaphore_tracker._fd = tracker_fd
fd = pipe_handle
exitcode = _main(fd)
sys.exit(exitcode)
示例6: main
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def main():
'''
Run code specified by data received over pipe
'''
assert is_forking(sys.argv)
handle = int(sys.argv[-1])
fd = msvcrt.open_osfhandle(handle, os.O_RDONLY)
from_parent = os.fdopen(fd, 'rb')
process.current_process()._inheriting = True
preparation_data = load(from_parent)
spawn.prepare(preparation_data)
self = load(from_parent)
process.current_process()._inheriting = False
from_parent.close()
exitcode = self._bootstrap()
exit(exitcode)
示例7: spawn_main
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def spawn_main(pipe_handle, parent_pid=None, tracker_fd=None):
'''
Run code specified by data received over pipe
'''
assert is_forking(sys.argv)
if sys.platform == 'win32':
import msvcrt
from .reduction import steal_handle
new_handle = steal_handle(parent_pid, pipe_handle)
fd = msvcrt.open_osfhandle(new_handle, os.O_RDONLY)
else:
from . import semaphore_tracker
semaphore_tracker._semaphore_tracker._fd = tracker_fd
fd = pipe_handle
exitcode = _main(fd)
sys.exit(exitcode)
示例8: wtrf
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def wtrf():
if sys.platform != "win32":
wt = int(os.environ['MYHDL_TO_PIPE'])
rf = int(os.environ['MYHDL_FROM_PIPE'])
else:
wt = msvcrt.open_osfhandle(int(os.environ['MYHDL_TO_PIPE']), os.O_APPEND | os.O_TEXT)
rf = msvcrt.open_osfhandle(int(os.environ['MYHDL_FROM_PIPE']), os.O_RDONLY | os.O_TEXT)
return wt, rf
示例9: _winapi_childhandle_after_createprocess_parent
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def _winapi_childhandle_after_createprocess_parent(self):
"""Called on Windows in the parent process after the CreateProcess()
system call. This method is intended to revert the actions performed
within `_winapi_childhandle_prepare_transfer()`. In particular, this
method is intended to prepare a subsequent call to the handle's
`close()` method.
"""
if WINAPI_HANDLE_TRANSFER_STEAL:
del self._parent_winapihandle
del self._parent_pid
# Setting `_fd` to None prevents the subsequent `close()` method
# invocation (triggered in `start_process()` after child creation)
# from actually calling `os.close()` on the file descriptor. This
# must be prevented because at this point the handle either already
# is or will be "stolen" by the child via a direct WinAPI call using
# the DUPLICATE_CLOSE_SOURCE option (and therefore become
# auto-closed, here, in the parent). The relative timing is not
# predictable. If the child process steals first, os.close() here
# would result in `OSError: [Errno 9] Bad file descriptor`. If
# os.close() is called on the handle in the parent before the child
# can steal the handle, a `OSError: [WinError 6] The handle is
# invalid` will be thrown in the child upon the stealing attempt.
self._fd = None
return
# Get C file descriptor from Windows file handle.
self._fd = msvcrt.open_osfhandle(
self._inheritable_winapihandle, self._fd_flag)
del self._inheritable_winapihandle
示例10: _writefd
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def _writefd(cls, conn, data, create_dummy_fds=False):
if create_dummy_fds:
for i in range(0, 256):
if not cls._is_fd_assigned(i):
os.dup2(conn.fileno(), i)
fd = reduction.recv_handle(conn)
if msvcrt:
fd = msvcrt.open_osfhandle(fd, os.O_WRONLY)
os.write(fd, data)
os.close(fd)
示例11: create_file_from_handle
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def create_file_from_handle(handle, mode="r"):
"""Return a Python :class:`file` arround a windows HANDLE"""
fd = msvcrt.open_osfhandle(handle, os.O_TEXT)
return os.fdopen(fd, mode, 0)
示例12: __init__
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def __init__(self, process_obj):
prep_data = spawn.get_preparation_data(process_obj._name)
# read end of pipe will be "stolen" by the child process
# -- see spawn_main() in spawn.py.
rhandle, whandle = _winapi.CreatePipe(None, 0)
wfd = msvcrt.open_osfhandle(whandle, 0)
cmd = spawn.get_command_line(parent_pid=os.getpid(),
pipe_handle=rhandle)
cmd = ' '.join('"%s"' % x for x in cmd)
with open(wfd, 'wb', closefd=True) as to_child:
# start process
try:
hp, ht, pid, tid = _winapi.CreateProcess(
spawn.get_executable(), cmd,
None, None, False, 0, None, None, None)
_winapi.CloseHandle(ht)
except:
_winapi.CloseHandle(rhandle)
raise
# set attributes of self
self.pid = pid
self.returncode = None
self._handle = hp
self.sentinel = int(hp)
util.Finalize(self, _winapi.CloseHandle, (self.sentinel,))
# send information to child
context.set_spawning_popen(self)
try:
reduction.dump(prep_data, to_child)
reduction.dump(process_obj, to_child)
finally:
context.set_spawning_popen(None)
示例13: __init__
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def __init__(self, process_obj):
prep_data = spawn.get_preparation_data(process_obj._name)
# read end of pipe will be "stolen" by the child process
# -- see spawn_main() in spawn.py.
rhandle, whandle = _winapi.CreatePipe(None, 0)
wfd = msvcrt.open_osfhandle(whandle, 0)
cmd = spawn.get_command_line(parent_pid=os.getpid(),
pipe_handle=rhandle)
cmd = ' '.join('"%s"' % x for x in cmd)
with open(wfd, 'wb', closefd=True) as to_child:
# start process
try:
hp, ht, pid, tid = _winapi.CreateProcess(
spawn.get_executable(), cmd,
None, None, False, 0, None, None, None)
_winapi.CloseHandle(ht)
except:
_winapi.CloseHandle(rhandle)
raise
# set attributes of self
self.pid = pid
self.returncode = None
self._handle = hp
self.sentinel = int(hp)
self.finalizer = util.Finalize(self, _winapi.CloseHandle, (self.sentinel,))
# send information to child
set_spawning_popen(self)
try:
reduction.dump(prep_data, to_child)
reduction.dump(process_obj, to_child)
finally:
set_spawning_popen(None)
示例14: spawn_main
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def spawn_main(pipe_handle, parent_pid=None, tracker_fd=None):
'''
Run code specified by data received over pipe
'''
assert is_forking(sys.argv), "Not forking"
if sys.platform == 'win32':
import msvcrt
new_handle = reduction.steal_handle(parent_pid, pipe_handle)
fd = msvcrt.open_osfhandle(new_handle, os.O_RDONLY)
else:
from . import semaphore_tracker
semaphore_tracker._semaphore_tracker._fd = tracker_fd
fd = pipe_handle
exitcode = _main(fd)
sys.exit(exitcode)
示例15: open_handle
# 需要导入模块: import msvcrt [as 别名]
# 或者: from msvcrt import open_osfhandle [as 别名]
def open_handle(handle, mode):
flags = 0
if 'w' not in mode and '+' not in mode:
flags |= os.O_RDONLY
if 'b' not in mode:
flags |= os.O_TEXT
if 'a' in mode:
flags |= os.O_APPEND
return msvcrt.open_osfhandle(handle, flags)