本文整理汇总了Python中os.set_blocking方法的典型用法代码示例。如果您正苦于以下问题:Python os.set_blocking方法的具体用法?Python os.set_blocking怎么用?Python os.set_blocking使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.set_blocking方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_wakeup_fd_result
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def test_set_wakeup_fd_result(self):
r1, w1 = os.pipe()
self.addCleanup(os.close, r1)
self.addCleanup(os.close, w1)
r2, w2 = os.pipe()
self.addCleanup(os.close, r2)
self.addCleanup(os.close, w2)
if hasattr(os, 'set_blocking'):
os.set_blocking(w1, False)
os.set_blocking(w2, False)
signal.set_wakeup_fd(w1)
self.assertEqual(signal.set_wakeup_fd(w2), w1)
self.assertEqual(signal.set_wakeup_fd(-1), w2)
self.assertEqual(signal.set_wakeup_fd(-1), -1)
示例2: test_set_wakeup_fd_blocking
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def test_set_wakeup_fd_blocking(self):
rfd, wfd = os.pipe()
self.addCleanup(os.close, rfd)
self.addCleanup(os.close, wfd)
# fd must be non-blocking
os.set_blocking(wfd, True)
with self.assertRaises(ValueError) as cm:
signal.set_wakeup_fd(wfd)
self.assertEqual(str(cm.exception),
"the fd %s must be in non-blocking mode" % wfd)
# non-blocking is ok
os.set_blocking(wfd, False)
signal.set_wakeup_fd(wfd)
signal.set_wakeup_fd(-1)
示例3: _set_nonblocking
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def _set_nonblocking(fd):
os.set_blocking(fd, False)
示例4: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def __init__(self, fd, map=None):
dispatcher.__init__(self, None, map)
self.connected = True
try:
fd = fd.fileno()
except AttributeError:
pass
self.set_file(fd)
# set it to non-blocking mode
os.set_blocking(fd, False)
示例5: check_wakeup
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def check_wakeup(self, test_body, *signals, ordered=True):
# use a subprocess to have only one thread
code = """if 1:
import _testcapi
import os
import signal
import struct
signals = {!r}
def handler(signum, frame):
pass
def check_signum(signals):
data = os.read(read, len(signals)+1)
raised = struct.unpack('%uB' % len(data), data)
if not {!r}:
raised = set(raised)
signals = set(signals)
if raised != signals:
raise Exception("%r != %r" % (raised, signals))
{}
signal.signal(signal.SIGALRM, handler)
read, write = os.pipe()
os.set_blocking(write, False)
signal.set_wakeup_fd(write)
test()
check_signum(signals)
os.close(read)
os.close(write)
""".format(tuple(map(int, signals)), ordered, test_body)
assert_python_ok('-c', code)
示例6: test_blocking
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def test_blocking(self):
self.check(os.get_blocking)
self.check(os.set_blocking, True)
示例7: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
super().__init__(extra)
self._extra['pipe'] = pipe
self._loop = loop
self._pipe = pipe
self._fileno = pipe.fileno()
self._protocol = protocol
self._closing = False
mode = os.fstat(self._fileno).st_mode
if not (stat.S_ISFIFO(mode) or
stat.S_ISSOCK(mode) or
stat.S_ISCHR(mode)):
self._pipe = None
self._fileno = None
self._protocol = None
raise ValueError("Pipe transport is for pipes/sockets only.")
os.set_blocking(self._fileno, False)
self._loop.call_soon(self._protocol.connection_made, self)
# only start reading when connection_made() has been called
self._loop.call_soon(self._loop._add_reader,
self._fileno, self._read_ready)
if waiter is not None:
# only wake up the waiter when connection_made() has been called
self._loop.call_soon(futures._set_result_unless_cancelled,
waiter, None)
示例8: remove_blocking
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def remove_blocking(fd: int) -> None:
os.set_blocking(fd, False)
示例9: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def __init__(self, fileobj):
assert not isinstance(fileobj, io.TextIOBase), 'Only binary mode files allowed'
super().__init__(fileobj)
os.set_blocking(int(self._fileno), False)
# Common bound methods
self._file_read = fileobj.read
self._readinto_impl = getattr(fileobj, 'readinto', None)
self._file_write = fileobj.write
示例10: __post_init__
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def __post_init__(self):
os.set_blocking(self.fileno, False)
示例11: _read_pages2
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def _read_pages2(book, background=False):
'''Index `book`.
If `background` is True, yield during long operations.
If `book` is already loaded, does nothing.
Upon return `book` will be in state DONE or FAILED.'''
if book.filename == manual_filename:
return book
if book.load_state == book_file.LoadState.DONE:
return book
try:
(r, w) = os.pipe2(os.O_CLOEXEC)
indexer.trigger_load(book.filename, w)
buf = None
if background:
os.set_blocking(r, False)
while not buf:
try:
buf = os.read(r, 10)
except BlockingIOError:
await asyncio.sleep(0)
else:
os.set_blocking(r, True)
buf = os.read(r, 10)
if buf != b'ok':
raise BookFileError(
'loading failed: {}'.format(book.filename))
log.info('loading complete for {}'.format(book.filename))
bookmarks = book.bookmarks
if indexer.get_page_count(book.filename) > 1:
# add an end-of-book bookmark
bookmarks += (indexer.get_page_count(book.filename) - 1,)
return book._replace(load_state=book_file.LoadState.DONE,
bookmarks=bookmarks,
num_pages=indexer.get_page_count(book.filename),
indexed=True)
except Exception:
log.warning('book loading failed for {}'.format(book.filename))
return book._replace(load_state=book_file.LoadState.FAILED)
示例12: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import set_blocking [as 别名]
def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
super().__init__(extra)
self._extra['pipe'] = pipe
self._loop = loop
self._pipe = pipe
self._fileno = pipe.fileno()
self._protocol = protocol
self._closing = False
self._paused = False
mode = os.fstat(self._fileno).st_mode
if not (stat.S_ISFIFO(mode) or
stat.S_ISSOCK(mode) or
stat.S_ISCHR(mode)):
self._pipe = None
self._fileno = None
self._protocol = None
raise ValueError("Pipe transport is for pipes/sockets only.")
os.set_blocking(self._fileno, False)
self._loop.call_soon(self._protocol.connection_made, self)
# only start reading when connection_made() has been called
self._loop.call_soon(self._loop._add_reader,
self._fileno, self._read_ready)
if waiter is not None:
# only wake up the waiter when connection_made() has been called
self._loop.call_soon(futures._set_result_unless_cancelled,
waiter, None)