本文整理汇总了Python中java.lang.Runtime.getRuntime方法的典型用法代码示例。如果您正苦于以下问题:Python Runtime.getRuntime方法的具体用法?Python Runtime.getRuntime怎么用?Python Runtime.getRuntime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.Runtime
的用法示例。
在下文中一共展示了Runtime.getRuntime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def __init__(self, console, history_file=default_history_file):
Runtime.getRuntime().addShutdownHook(Thread(self))
self.history_file = history_file
self.history = []
self.loadHistory()
self.console = console
self.index = len(self.history) - 1
self.last = ""
示例2: run
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def run(self, options, args):
if options.supported or options.supported_html:
return storytext.guishared.ScriptEngine.run(self, options, args)
class ShutdownHook(Thread):
def run(tself):#@NoSelf
self.cleanup(options.interface)
if not options.disable_usecase_names:
hook = ShutdownHook()
Runtime.getRuntime().addShutdownHook(hook)
return storytext.scriptengine.ScriptEngine.run(self, options, args)
示例3: actionPerformed
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def actionPerformed(self, event):
browsers = ["google-chrome", "firefox", "opera", "epiphany", "konqueror", "conkeror", "midori", "kazehakase", "mozilla"]
osName = System.getProperty("os.name")
helpHTML = ClassLoader.getSystemResource("help.html").toString()
if osName.find("Mac OS") == 0:
Class.forName("com.apple.eio.FileManager").getDeclaredMethod( "openURL", [String().getClass()]).invoke(None, [helpHTML])
elif osName.find("Windows") == 0:
Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + helpHTML)
else:
browser = None
for b in browsers:
if browser == None and Runtime.getRuntime().exec(["which", b]).getInputStream().read() != -1:
browser = b
Runtime.getRuntime().exec([browser, helpHTML])
示例4: browseURI
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def browseURI(uri):
osName = System.getProperty("os.name")
rt = Runtime.getRuntime()
if osName.startswith("Mac OS"):
rt.exec('open "%s"' % uri)
else:
if osName.startswith("Windows"):
ProcessBuilder(["cmd", "/C", "start", uri]).start()
else:
browsers = ["google-chrome", "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"]
for b in browsers:
exists = rt.exec("which %s" % b).getInputStream().read()
if exists != -1:
Runtime.getRuntime().exec("%s %s" % (b, uri))
return
示例5: launchProgramNoWait
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def launchProgramNoWait(args, workingDir = None):
if workingDir != None and not isinstance(workingDir, File):
workingDir = File(workingDir)
process = Runtime.getRuntime().exec(args, None, workingDir)
OutputThread(process.getInputStream(), System.out).start()
OutputThread(process.getErrorStream(), System.err).start()
return process
示例6: syslog
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def syslog( level, message ):
try:
ps = Runtime.getRuntime().exec(['logger', '-p', '%s.%s' % (LogConfig.syslogFacility, level), '-t', LogConfig.syslogTag, message])
return ps.waitFor()
except:
log(INFO_, level + " " + message)
return 0
示例7: cpu_count
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def cpu_count():
# Python 2.6+
try:
import multiprocessing
return multiprocessing.cpu_count()
except (ImportError, NotImplementedError):
pass
# POSIX
try:
import os
res = int(os.sysconf('SC_NPROCESSORS_ONLN'))
if res > 0:
return res
except (AttributeError, ValueError):
pass
# Windows
try:
res = int(os.environ['NUMBER_OF_PROCESSORS'])
if res > 0:
return res
except (KeyError, ValueError):
pass
# jython
try:
from java.lang import Runtime
runtime = Runtime.getRuntime()
res = runtime.availableProcessors()
if res > 0:
return res
except ImportError:
pass
# BSD
try:
import subprocess
sysctl = subprocess.Popen(['sysctl', '-n', 'hw.ncpu'],
stdout=subprocess.PIPE)
scStdout = sysctl.communicate()[0]
res = int(scStdout)
if res > 0:
return res
except (OSError, ValueError):
pass
# Linux
try:
res = open('/proc/cpuinfo').read().count('processor\t:')
if res > 0:
return res
except IOError:
pass
return 0
示例8: cachedBlast
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def cachedBlast(fileName, blastLocation, database, eValue, query, pipeline, force = False):
"""
Performs a blast search using the blastp executable and database in blastLocation on
the query with the eValue. The result is an XML file saved to fileName. If fileName
already exists the search is skipped. If remote is true then the search is done remotely.
"""
if not os.path.isfile(fileName) or force:
output = open(fileName, "w")
command = [blastLocation + "/bin/blastp",
"-evalue", str(eValue),
"-outfmt", "5",
"-query", query,
"-num_threads", str(Runtime.getRuntime().availableProcessors()),
"-db", database]
blastProcess = subprocess.Popen(command,
stdout = output)
while blastProcess.poll() == None:
if pipeline.exception:
print "Stopping in blast"
psProcess = subprocess.Popen(["ps", "aux"], stdout = subprocess.PIPE)
awkProcess = subprocess.Popen(["awk", "/" + " ".join(command).replace("/", "\\/") + "/"], stdin = psProcess.stdout, stdout = subprocess.PIPE)
for line in awkProcess.stdout:
subprocess.Popen(["kill", "-9", re.split(r"\s+", line)[1]])
output.close()
raise pipeline.exception
if blastProcess.poll() != 0:
raise OSError()
output.close()
try:
return parseBlast(fileName)
except SAXParseException:
print 'Retry'
return cachedBlast(fileName, blastLocation, database, eValue, query, pipeline, True)
示例9: cpu_count
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def cpu_count():
"""Returns the number of cpus"""
# jython
try:
from java.lang import Runtime
runtime = Runtime.getRuntime()
res = runtime.availableProcessors()
if res > 0:
return res
except ImportError:
pass
# POSIX
try:
res = int(os.sysconf('SC_NPROCESSORS_ONLN'))
if res > 0:
return res
except (AttributeError,ValueError):
pass
# Windows
try:
res = int(os.environ['NUMBER_OF_PROCESSORS'])
if res > 0:
return res
except (KeyError, ValueError):
pass
#Could not get the number of cpus. Return 1
return 1
示例10: system
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def system(cmd):
"""
system(cmd): executes cmd in a shell
Jpython currently lacks a system command in its os module. This is
a temporary filler in till a better one comes along the way
"""
r= Runtime.getRuntime()
try:
p = r.exec(cmd)
p.waitFor()
except:
raise 'Error executing shell command: ' + cmd
lnr_err = LineNumberReader(InputStreamReader(p.getErrorStream()))
err_lines = []
while 1:
line_err = lnr_err.readLine()
if not line_err:
break
else:
print line_err
#
lnr = LineNumberReader(InputStreamReader(p.getInputStream()))
#lines = []
while 1:
line = lnr.readLine()
if not line:
break
else:
print line
示例11: init
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def init(self, config):
#self._numWorkers = 1
self._numWorkers = Runtime.getRuntime().availableProcessors()
self._maximaPath = config["maximaPath"]
self._threadPool = ThreadPool(self._numWorkers)
self._maximaPool = Queue.Queue(self._numWorkers)
for i in range(self._numWorkers):
self.launchMaximaInstance()
示例12: main
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def main():
global myarg0
try:
myarg0
except NameError:
print "Please input the class you want to open source file"
return
path = "/home/LiGeng/Desktop/Javasrc"
s = myarg0.split(".")
for x in s:
path = ("%s/%s")%(path, x)
path = ("%s.java") % path
print path
Runtime.getRuntime().exec(("emacs %s")%path)
示例13: run
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def run(string, args=[], callback=None, callbackOnErr=False):
def out (exit, call, inp, err):
return {
"exitCode": exit,
"callbackReturn": call,
"inputArray": inp,
"errorArray": err
}
tmp = File.createTempFile('tmp', None)
tmp.setExecutable(True)
writer = FileOutputStream(tmp);
writer.write(string)
writer.flush()
writer.close()
try:
process = Runtime.getRuntime().exec([tmp.getAbsolutePath()] + ([str(i) for i in args] or []))
process.waitFor()
inp = BufferedReader(InputStreamReader(process.getInputStream()))
err = BufferedReader(InputStreamReader(process.getErrorStream()))
errFlag = False
inputArray = []
errorArray = []
holder = inp.readLine()
while holder != None:
print holder
inputArray += [holder]
holder = inp.readLine()
holder = err.readLine()
while holder != None:
errFlag = True
errorArray += [holder]
holder = err.readLine()
tmp.delete()
if errFlag:
if callback and callbackOnErr: return out(1, callback(out(1, None, inputArray, errorArray)), inputArray, errorArray)
else: return out(1, None, inputArray, errorArray)
else:
if callback: return out(0, callback(out(0, None, inputArray, [])), inputArray, [])
else: return out(0, None, inputArray, [])
except Exception as e:
print str(e)
tmp.delete()
if callback and callbackOnErr: return out(3, callback(out(3, None, [], str(e).split("\n"))), [], str(e).split("\n"))
else: return out(3, None, [], str(e).split("\n"))
示例14: play
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def play(self):
num_threads = Runtime.getRuntime().availableProcessors()
executor = Executors.newFixedThreadPool(num_threads)
callables = [_Worker(start_pos) for start_pos in self.positions]
futures = executor.invokeAll(callables)
# calculate stats
for future in futures:
worker = future.get()
self.process_scores(worker)
executor.shutdown()
示例15: get_cpu_count
# 需要导入模块: from java.lang import Runtime [as 别名]
# 或者: from java.lang.Runtime import getRuntime [as 别名]
def get_cpu_count():
cpu_count = 1
if os.name == 'java':
from java.lang import Runtime
runtime = Runtime.getRuntime()
cpu_count = runtime.availableProcessors()
else:
import multiprocessing
cpu_count = multiprocessing.cpu_count()
return cpu_count