本文整理汇总了Python中twisted.internet.error.ProcessExitedAlready方法的典型用法代码示例。如果您正苦于以下问题:Python error.ProcessExitedAlready方法的具体用法?Python error.ProcessExitedAlready怎么用?Python error.ProcessExitedAlready使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.error
的用法示例。
在下文中一共展示了error.ProcessExitedAlready方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: signalProcess
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def signalProcess(self, signalID):
"""
Send the given signal C{signalID} to the process. It'll translate a
few signals ('HUP', 'STOP', 'INT', 'KILL', 'TERM') from a string
representation to its int value, otherwise it'll pass directly the
value provided
@type signalID: C{str} or C{int}
"""
if signalID in ('HUP', 'STOP', 'INT', 'KILL', 'TERM'):
signalID = getattr(signal, 'SIG%s' % (signalID,))
if self.pid is None:
raise ProcessExitedAlready()
try:
os.kill(self.pid, signalID)
except OSError as e:
if e.errno == errno.ESRCH:
raise ProcessExitedAlready()
else:
raise
示例2: test_openingTTY
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def test_openingTTY(self):
scriptPath = b"twisted.test.process_tty"
p = Accumulator()
d = p.endedDeferred = defer.Deferred()
reactor.spawnProcess(p, pyExe, [pyExe, b"-u", b"-m", scriptPath],
env=properEnv, usePTY=self.usePTY)
p.transport.write(b"hello world!\n")
def processEnded(ign):
self.assertRaises(
error.ProcessExitedAlready, p.transport.signalProcess, 'HUP')
self.assertEqual(
p.outF.getvalue(),
b"hello world!\r\nhello world!\r\n",
("Error message from process_tty "
"follows:\n\n%s\n\n" % (p.outF.getvalue(),)))
return d.addCallback(processEnded)
示例3: testOpeningTTY
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def testOpeningTTY(self):
exe = sys.executable
scriptPath = util.sibpath(__file__, "process_tty.py")
p = Accumulator()
d = p.endedDeferred = defer.Deferred()
reactor.spawnProcess(p, exe, [exe, "-u", scriptPath], env=None,
path=None, usePTY=self.usePTY)
p.transport.write("hello world!\n")
def processEnded(ign):
self.assertRaises(
error.ProcessExitedAlready, p.transport.signalProcess, 'HUP')
self.assertEquals(
p.outF.getvalue(),
"hello world!\r\nhello world!\r\n",
"Error message from process_tty follows:\n\n%s\n\n" % p.outF.getvalue())
return d.addCallback(processEnded)
示例4: stopProcess
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def stopProcess(self, name):
"""
@param name: The name of the process to be stopped
"""
if name not in self.processes:
raise KeyError('Unrecognized process name: %s' % (name,))
proto = self.protocols.get(name, None)
if proto is not None:
proc = proto.transport
try:
proc.signalProcess('TERM')
except error.ProcessExitedAlready:
pass
else:
self.murder[name] = self._reactor.callLater(
self.killTime,
self._forceStopProcess, proc)
示例5: kill
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def kill(self):
try:
self.transport.signalProcess('KILL')
except internet_error.ProcessExitedAlready:
self.log.debug('Process Exited Already')
示例6: signalProcess
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def signalProcess(self, signalID):
if self.pid is None:
raise error.ProcessExitedAlready()
if signalID in ("INT", "TERM", "KILL"):
win32process.TerminateProcess(self.hProcess, 1)
示例7: closed
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def closed(self):
if self.ptyTuple and os.path.exists(self.ptyTuple[2]):
ttyGID = os.stat(self.ptyTuple[2])[5]
os.chown(self.ptyTuple[2], 0, ttyGID)
if self.pty:
try:
self.pty.signalProcess('HUP')
except (OSError, ProcessExitedAlready):
pass
self.pty.loseConnection()
self.addUTMPEntry(0)
log.msg('shell closed')
示例8: tearDown
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def tearDown(self):
# Kill the child process. We're done with it.
try:
self.clientTransport.signalProcess("KILL")
except (error.ProcessExitedAlready, OSError):
pass
def trap(failure):
failure.trap(error.ProcessTerminated)
self.assertIsNone(failure.value.exitCode)
self.assertEqual(failure.value.status, 9)
return self.testTerminal.onDisconnection.addErrback(trap)
示例9: _reallyDie
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def _reallyDie(self):
try:
self.transport.signalProcess('KILL')
except ProcessExitedAlready:
pass
示例10: test_process
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def test_process(self):
"""
Test running a process: check its output, it exitCode, some property of
signalProcess.
"""
scriptPath = b"twisted.test.process_tester"
d = defer.Deferred()
p = TestProcessProtocol()
p.deferred = d
reactor.spawnProcess(p, pyExe, [pyExe, b"-u", b"-m", scriptPath],
env=properEnv)
def check(ignored):
self.assertEqual(p.stages, [1, 2, 3, 4, 5])
f = p.reason
f.trap(error.ProcessTerminated)
self.assertEqual(f.value.exitCode, 23)
# would .signal be available on non-posix?
# self.assertIsNone(f.value.signal)
self.assertRaises(
error.ProcessExitedAlready, p.transport.signalProcess, 'INT')
try:
import process_tester, glob
for f in glob.glob(process_tester.test_file_match):
os.remove(f)
except:
pass
d.addCallback(check)
return d
示例11: test_killExited
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def test_killExited(self):
"""
L{process.Process.signalProcess} raises L{error.ProcessExitedAlready}
if the process has exited.
"""
self.mockos.child = False
cmd = b'/mock/ouch'
p = TrivialProcessProtocol(None)
proc = reactor.spawnProcess(p, cmd, [b'ouch'], env=None, usePTY=False)
# We didn't specify a waitpid value, so the waitpid call in
# registerReapProcessHandler has already reaped the process
self.assertRaises(error.ProcessExitedAlready,
proc.signalProcess, "KILL")
示例12: test_killExitedButNotDetected
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def test_killExitedButNotDetected(self):
"""
L{process.Process.signalProcess} raises L{error.ProcessExitedAlready}
if the process has exited but that twisted hasn't seen it (for example,
if the process has been waited outside of twisted): C{os.kill} then
raise C{OSError} with C{errno.ESRCH} as errno.
"""
self.mockos.child = False
self.mockos.waitChild = (0, 0)
cmd = b'/mock/ouch'
p = TrivialProcessProtocol(None)
proc = reactor.spawnProcess(p, cmd, [b'ouch'], env=None, usePTY=False)
self.mockos.raiseKill = OSError(errno.ESRCH, "Not found")
self.assertRaises(error.ProcessExitedAlready,
proc.signalProcess, "KILL")
示例13: _forceStopProcess
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def _forceStopProcess(self, proc):
"""
@param proc: An L{IProcessTransport} provider
"""
try:
proc.signalProcess('KILL')
except error.ProcessExitedAlready:
pass
示例14: connectionMade
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def connectionMade(self):
@defer.inlineCallbacks
def killIfAlive():
try:
yield self.transport.signalProcess('KILL')
log.msg('Killed source proccess: Timeout %s exceeded' % self.timeout)
except error.ProcessExitedAlready:
pass
self.timer = reactor.callLater(self.timeout, killIfAlive)
示例15: _terminate
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 别名]
def _terminate(self, warn=False):
if self.transport is not None:
if warn:
warning("%s didn't exit. Sending SIGTERM"
% (self.daemon.program,))
try:
self.transport.signalProcess(signal.SIGTERM)
except ProcessExitedAlready:
pass
else:
# Give some time for the process, and then show who's the boss.
delayed = reactor.callLater(SIGKILL_DELAY, self._really_kill)
self._delayed_really_kill = delayed