Back to index

python3.2  3.2.2
Public Member Functions
test.test_signal.SiginterruptTest Class Reference

List of all members.

Public Member Functions

def readpipe_interrupted
def test_without_siginterrupt
def test_siginterrupt_on
def test_siginterrupt_off

Detailed Description

Definition at line 312 of file test_signal.py.


Member Function Documentation

Perform a read during which a signal will arrive.  Return True if the
read is interrupted by the signal and raises an exception.  Return False
if it returns normally.

Definition at line 314 of file test_signal.py.

00314 
00315     def readpipe_interrupted(self, interrupt):
00316         """Perform a read during which a signal will arrive.  Return True if the
00317         read is interrupted by the signal and raises an exception.  Return False
00318         if it returns normally.
00319         """
00320         class Timeout(Exception):
00321             pass
00322 
00323         # use a subprocess to have only one thread, to have a timeout on the
00324         # blocking read and to not touch signal handling in this process
00325         code = """if 1:
00326             import errno
00327             import os
00328             import signal
00329             import sys
00330 
00331             interrupt = %r
00332             r, w = os.pipe()
00333 
00334             def handler(signum, frame):
00335                 pass
00336 
00337             signal.signal(signal.SIGALRM, handler)
00338             if interrupt is not None:
00339                 signal.siginterrupt(signal.SIGALRM, interrupt)
00340 
00341             print("ready")
00342             sys.stdout.flush()
00343 
00344             # run the test twice
00345             for loop in range(2):
00346                 # send a SIGALRM in a second (during the read)
00347                 signal.alarm(1)
00348                 try:
00349                     # blocking call: read from a pipe without data
00350                     os.read(r, 1)
00351                 except OSError as err:
00352                     if err.errno != errno.EINTR:
00353                         raise
00354                 else:
00355                     sys.exit(2)
00356             sys.exit(3)
00357         """ % (interrupt,)
00358         with spawn_python('-c', code) as process:
00359             try:
00360                 # wait until the child process is loaded and has started
00361                 first_line = process.stdout.readline()
00362 
00363                 # Wait the process with a timeout of 5 seconds
00364                 timeout = time.time() + 5.0
00365                 while True:
00366                     if timeout < time.time():
00367                         raise Timeout()
00368                     status = process.poll()
00369                     if status is not None:
00370                         break
00371                     time.sleep(0.1)
00372 
00373                 stdout, stderr = process.communicate()
00374             except Timeout:
00375                 process.kill()
00376                 return False
00377             else:
00378                 stdout = first_line + stdout
00379                 exitcode = process.wait()
00380                 if exitcode not in (2, 3):
00381                     raise Exception("Child error (exit code %s): %s"
00382                                     % (exitcode, stdout))
00383                 return (exitcode == 3)

Here is the caller graph for this function:

Definition at line 398 of file test_signal.py.

00398 
00399     def test_siginterrupt_off(self):
00400         # If a signal handler is installed and siginterrupt is called with
00401         # a false value for the second argument, when that signal arrives, it
00402         # does not interrupt a syscall that's in progress.
00403         interrupted = self.readpipe_interrupted(False)
00404         self.assertFalse(interrupted)
00405 
00406 
@unittest.skipIf(sys.platform == "win32", "Not valid on Windows")

Here is the call graph for this function:

Definition at line 391 of file test_signal.py.

00391 
00392     def test_siginterrupt_on(self):
00393         # If a signal handler is installed and siginterrupt is called with
00394         # a true value for the second argument, when that signal arrives, it
00395         # interrupts a syscall that's in progress.
00396         interrupted = self.readpipe_interrupted(True)
00397         self.assertTrue(interrupted)

Here is the call graph for this function:

Definition at line 384 of file test_signal.py.

00384 
00385     def test_without_siginterrupt(self):
00386         # If a signal handler is installed and siginterrupt is not called
00387         # at all, when that signal arrives, it interrupts a syscall that's in
00388         # progress.
00389         interrupted = self.readpipe_interrupted(None)
00390         self.assertTrue(interrupted)

Here is the call graph for this function:


The documentation for this class was generated from the following file: