本文整理汇总了Python中select.error函数的典型用法代码示例。如果您正苦于以下问题:Python error函数的具体用法?Python error怎么用?Python error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select
def select(cls, rlist, wlist, xlist, timeout=5):
the_time = time.time()
if timeout is not None:
tstop = the_time + timeout
else:
tstop = 0
while timeout is None or the_time <= tstop:
# we must always go around at least once
rs = []
ws = []
for r in rlist:
try:
if r.recv_pipe.canread():
rs.append(r)
except IOError:
# raise a socket error
raise select.error(errno.EPIPE, os.strerror(errno.EPIPE))
for w in wlist:
try:
if w.send_pipe.canwrite():
ws.append(w)
except IOError:
# raise a socket error
raise select.error(errno.EPIPE, os.strerror(errno.EPIPE))
if rs or ws:
return rs, ws, []
else:
time.sleep(1)
the_time = time.time()
return [], [], []
示例2: test_select_eintr
def test_select_eintr(self):
# EINTR is supposed to be ignored
with mock.patch('pyftpdlib.ioloop.select.select',
side_effect=select.error()) as m:
m.side_effect.errno = errno.EINTR
s, rd, wr = self.test_register()
s.poll(0)
# ...but just that
with mock.patch('pyftpdlib.ioloop.select.select',
side_effect=select.error()) as m:
m.side_effect.errno = errno.EBADF
s, rd, wr = self.test_register()
self.assertRaises(select.error, s.poll, 0)
示例3: test_invalidate_connection
def test_invalidate_connection(slef, queued_pool):
msg = Message.generate()
with pytest.raises(select.error):
with queued_pool.acquire() as cxn:
fairy = cxn.fairy
raise select.error(9, 'Bad file descriptor')
assert fairy.cxn.is_closed
示例4: __call__
def __call__(self, *args):
self.called += 1
if self.called == 1:
# raise the exception on first call
raise select.error(errno.EINTR, os.strerror(errno.EINTR))
else:
# Return real select value for consecutive calls
return old_select(*args)
示例5: test_nofailure_with_errno_EINTR
def test_nofailure_with_errno_EINTR(self):
"""checks no exception is raised if errno.EINTR is raised
while it's selecting"""
self.__call_count = 0
select.select = lambda r, w, x, t: self.__faked_select(
select.error(errno.EINTR))
self.stats_httpd = MyStatsHttpd(get_availaddr())
self.stats_httpd.start() # shouldn't leak the exception
self.assertFalse(self.stats_httpd.running)
self.assertIsNone(self.stats_httpd.mccs)
示例6: test_ppl
def test_ppl(self, read_mock, select_mock):
# Simulate the two files
stdout = mock.Mock(name='pipe.stdout')
stdout.fileno.return_value = 65
stderr = mock.Mock(name='pipe.stderr')
stderr.fileno.return_value = 66
# Recipients for results
out_list = []
err_list = []
# StreamLineProcessors
out_proc = StreamLineProcessor(stdout, out_list.append)
err_proc = StreamLineProcessor(stderr, err_list.append)
# The select call always returns all the streams
select_mock.side_effect = [
[[out_proc, err_proc], [], []],
select.error(errno.EINTR), # Test interrupted system call
[[out_proc, err_proc], [], []],
[[out_proc, err_proc], [], []],
]
# The read calls return out and err interleaved
# Lines are split in various ways, to test all the code paths
read_mock.side_effect = ['line1\nl'.encode('utf-8'),
'err'.encode('utf-8'),
'ine2'.encode('utf-8'),
'1\nerr2\n'.encode('utf-8'),
'', '',
Exception] # Make sure it terminates
command_wrappers.Command.pipe_processor_loop([out_proc, err_proc])
# Check the calls order and the output
assert read_mock.mock_calls == [
mock.call(65, 4096),
mock.call(66, 4096),
mock.call(65, 4096),
mock.call(66, 4096),
mock.call(65, 4096),
mock.call(66, 4096),
]
assert out_list == ['line1', 'line2']
assert err_list == ['err1', 'err2', '']
示例7: poll
def poll(self, timeout):
if self.error:
raise select.error(self.error)
return self.result
示例8: select
def select(self, r, w, x, timeout):
if self.error:
raise select.error(self.error)
return self.readables, self.writables, []
示例9: select
def select(self, r, w, x, timeout):
import select
if self.select_error:
raise select.error(self.select_error)
return self.select_result
示例10: test_ppl_select_failure
def test_ppl_select_failure(self, select_mock):
# Test if select errors are passed through
select_mock.side_effect = select.error('not good')
with pytest.raises(select.error):
command_wrappers.Command.pipe_processor_loop([None])
示例11: raise_eintr_once
def raise_eintr_once(*args):
select_call.side_effect = None
raise select.error(4, "Interrupted system call")
示例12: test_read_select_err
def test_read_select_err(self):
'''Recovers from select errors'''
with mock.patch('nsq.client.select.select') as mock_select:
mock_select.side_effect = select.error(errno.EBADF)
# This test passes if no exception is raised
self.client.read()
示例13: test_internal_utils
def test_internal_utils(self):
err = select.error(errno.EINTR, "interrupted")
assert omcache._select_errno(err) == errno.EINTR
示例14: raise_eintr
def raise_eintr():
raise select.error(4, 'Interrupted system call')
示例15: raise_select_except
def raise_select_except(*args):
raise select.error('dummy error')