示例#1
0
  def launch_repl(self, pex, **pex_run_kwargs):
    # While the repl subprocess is synchronously spawned, we rely on process group
    # signalling for a SIGINT to reach the repl subprocess directly - and want to
    # do nothing in response on the parent side.
    def ignore_control_c(signum, frame): pass

    with signal_handler_as(signal.SIGINT, ignore_control_c):
      env = pex_run_kwargs.pop('env', os.environ).copy()
      pex.run(env=env, **pex_run_kwargs)
示例#2
0
 def test_signal_handler_as(self):
   mock_initial_handler = 1
   mock_new_handler = 2
   with mock.patch('signal.signal', **PATCH_OPTS) as mock_signal:
     mock_signal.return_value = mock_initial_handler
     try:
       with signal_handler_as(signal.SIGUSR2, mock_new_handler):
         raise NotImplementedError('blah')
     except NotImplementedError:
       pass
   self.assertEquals(mock_signal.call_count, 2)
   mock_signal.assert_has_calls([
     mock.call(signal.SIGUSR2, mock_new_handler),
     mock.call(signal.SIGUSR2, mock_initial_handler)
   ])
示例#3
0
 def test_signal_handler_as(self):
     mock_initial_handler = 1
     mock_new_handler = 2
     with unittest.mock.patch('signal.signal', **PATCH_OPTS) as mock_signal:
         mock_signal.return_value = mock_initial_handler
         try:
             with signal_handler_as(signal.SIGUSR2, mock_new_handler):
                 raise NotImplementedError('blah')
         except NotImplementedError:
             pass
     self.assertEqual(mock_signal.call_count, 2)
     mock_signal.assert_has_calls([
         unittest.mock.call(signal.SIGUSR2, mock_new_handler),
         unittest.mock.call(signal.SIGUSR2, mock_initial_handler)
     ])
示例#4
0
    def launch_repl(self, perl6_env):
        # TODO: this is a massive hack that should be removed from python_repl.py (this is the leading
        # cause of interactivity issues in america!).
        def ignore_control_c(signum, frame):
            pass

        with signal_handler_as(signal.SIGINT, ignore_control_c):
            try:
                # When called with no arguments, drops into a repl.
                return self._perl6.invoke_perl6([], perl6_env)
            except Perl6.Perl6InvocationError as e:
                raise self.Perl6ReplError(
                    "Error in the perl6 repl: {}".format(e),
                    e,
                    exit_code=e.exit_code)