本文整理匯總了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