本文整理汇总了Python中typhon.vats.currentVat.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recv
def recv(self, atom, args):
from typhon.objects.collections.maps import EMPTY_MAP
if atom is FROMNOW_1:
duration = promoteToDouble(args[0])
p, r = makePromise()
vat = currentVat.get()
uv_timer = ruv.alloc_timer(vat.uv_loop)
# Stash the resolver.
ruv.stashTimer(uv_timer, (vat, r))
# repeat of 0 means "don't repeat"
ruv.timerStart(uv_timer, resolveTimer, int(duration * 1000), 0)
assert ruv.isActive(uv_timer), "Timer isn't active!?"
return p
if atom is TRIAL_1:
obj = args[0]
then = time.time()
obj.call(u"run", [])
now = time.time()
# We can't give the value up immediately, due to determinism
# requirements. Instead, provide it as a promise which will be
# available on subsequent turns.
rv = DoubleObject(now - then)
p, r = makePromise()
vat = currentVat.get()
vat.sendOnly(r, RESOLVE_1, [rv], EMPTY_MAP)
return p
raise Refused(self, atom, args)
示例2: setContents
def setContents(self, data):
sibling = self.temporarySibling(".setContents")
p, r = makePromise()
vat = currentVat.get()
path = sibling.asBytes()
# Use CREAT | EXCL to cause a failure if the temporary file
# already exists.
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
with io:
f = 0
try:
f = ruv.magic_fsOpen(vat, path, flags, 0777)
except object as err:
smash(r, StrObject(u"Couldn't open file fount: %s" % err))
else:
try:
writeLoop(f, data)
except object as err:
ruv.magic_fsClose(vat, f)
smash(r, StrObject(u"libuv error: %s" % err))
else:
ruv.magic_fsClose(vat, f)
ruv.magic_fsRename(vat, path, self.asBytes())
resolve(r, NullObject)
return p
示例3: whenResolvedOnly
def whenResolvedOnly(self, o, callback):
from typhon.objects.collections.maps import EMPTY_MAP
vat = currentVat.get()
vat.sendOnly(o, _WHENMORERESOLVED_1,
[WhenResolvedReactor(callback, o, None, vat)],
EMPTY_MAP)
return NullObject
示例4: makeProcess
def makeProcess(executable, args, environment):
"""
Create a subordinate process on the current node from the given
executable, arguments, and environment.
"""
# Third incarnation: libuv-powered and requiring bytes.
executable = unwrapBytes(executable)
# This could be an LC, but doing it this way fixes the RPython annotation
# for the list to be non-None.
argv = []
for arg in unwrapList(args):
s = unwrapBytes(arg)
assert s is not None, "proven impossible by hand"
argv.append(s)
env = {}
for (k, v) in unwrapMap(environment).items():
env[unwrapBytes(k)] = unwrapBytes(v)
packedEnv = [k + '=' + v for (k, v) in env.items()]
vat = currentVat.get()
try:
process = ruv.allocProcess()
sub = SubProcess(vat, process, argv, env)
ruv.spawn(vat.uv_loop, process,
file=executable, args=argv, env=packedEnv)
sub.retrievePID()
return sub
except ruv.UVError as uve:
raise userError(u"makeProcess: Couldn't spawn process: %s" %
uve.repr().decode("utf-8"))
示例5: makeStdErr
def makeStdErr():
vat = currentVat.get()
uv_loop = vat.uv_loop
tty = ruv.alloc_tty(uv_loop, 2, False)
# ruv.TTYSetMode(tty, ruv.TTY_MODE_RAW)
return StreamDrain(ruv.rffi.cast(ruv.stream_tp, tty), vat)
示例6: run
def run(self, executable, argv, env, stdinFount=None, stdoutDrain=None,
stderrDrain=None, stdin=False, stdout=False, stderr=False):
# Sixth incarnation: Now with streamcaps!
# Unwrap argv.
l = []
for arg in argv:
bs = unwrapBytes(arg)
assert bs is not None, "proven impossible"
l.append(bs)
argv = l
# Unwrap and prep environment.
d = {}
for (k, v) in env.items():
d[unwrapBytes(k)] = unwrapBytes(v)
packedEnv = [k + '=' + v for (k, v) in d.items()]
env = d
vat = currentVat.get()
# Set up the list of streams and attach streamcaps.
stdinSink = nullSink
stdoutSource = stderrSource = emptySource
streams = []
if stdin:
stream = ruv.rffi.cast(ruv.stream_tp,
ruv.alloc_pipe(vat.uv_loop))
streams.append(stream)
wrapped = ruv.wrapStream(stream, 1)
stdinSink = StreamSink(wrapped, vat)
else:
streams.append(nullptr(ruv.stream_t))
if stdout:
stream = ruv.rffi.cast(ruv.stream_tp,
ruv.alloc_pipe(vat.uv_loop))
streams.append(stream)
wrapped = ruv.wrapStream(stream, 1)
stdoutSource = StreamSource(wrapped, vat)
else:
streams.append(nullptr(ruv.stream_t))
if stderr:
stream = ruv.rffi.cast(ruv.stream_tp,
ruv.alloc_pipe(vat.uv_loop))
streams.append(stream)
wrapped = ruv.wrapStream(stream, 1)
stderrSource = StreamSource(wrapped, vat)
else:
streams.append(nullptr(ruv.stream_t))
try:
process = ruv.allocProcess()
sub = SubProcess(vat, process, argv, env, stdin=stdinSink,
stdout=stdoutSource, stderr=stderrSource)
vat.enqueueEvent(SpawnProcessIOEvent(
vat, sub, process, executable, argv, packedEnv, streams))
return sub
except ruv.UVError as uve:
raise userError(u"makeProcess: Couldn't spawn process: %s" %
uve.repr().decode("utf-8"))
示例7: run
def run(self, unused):
from typhon.objects.collections.maps import EMPTY_MAP
if self.done:
return
if self._ref.isResolved():
if isBroken(self._ref):
f = self._eb
else:
f = self._cb
try:
outcome = f.call(u"run", [self._ref])
if not isBroken(self._ref) and isBroken(outcome):
# success arm returned a broken promise
outcome = self._eb.call(u"run", [outcome])
self._resolver.resolve(outcome)
except UserException as ue:
from typhon.objects.exceptions import sealException
if not isBroken(self._ref):
# success arm threw
try:
self._resolver.resolve(self._eb.call(u"run", [UnconnectedRef(currentVat.get(), sealException(ue))]))
except UserException as ue2:
self._resolver.smash(sealException(ue2))
else:
# failure arm threw
self._resolver.smash(sealException(ue))
self.done = True
else:
self.vat.sendOnly(self._ref, _WHENMORERESOLVED_1, [self],
EMPTY_MAP)
示例8: _whenMoreResolved
def _whenMoreResolved(self, callback):
from typhon.objects.collections.maps import EMPTY_MAP
# Welcome to _whenMoreResolved.
# This method's implementation, in Monte, should be:
# to _whenMoreResolved(callback): callback<-(self)
vat = currentVat.get()
vat.sendOnly(callback, RUN_1, [self], EMPTY_MAP)
return NullObject
示例9: makeProxy
def makeProxy(handler, resolutionBox, resolved):
if not handler.isSettled():
raise userError(u"Proxy handler not settled")
vat = currentVat.get()
if resolved:
return FarRef(vat, handler, resolutionBox)
else:
return RemotePromise(vat, handler, resolutionBox)
示例10: whenNear
def whenNear(self, o, callback):
from typhon.objects.collections.maps import EMPTY_MAP
p, r = makePromise()
vat = currentVat.get()
vat.sendOnly(o, _WHENMORERESOLVED_1,
[WhenNearReactor(callback, o, r, vat)],
EMPTY_MAP)
return p
示例11: makeStdIn
def makeStdIn():
vat = currentVat.get()
uv_loop = vat.uv_loop
stdinKind = ruv.guess_handle(0)
if stdinKind == ruv.HANDLE_TTY:
stdin = ruv.alloc_tty(uv_loop, 0, True)
return StreamFount(ruv.rffi.cast(ruv.stream_tp, stdin), vat)
else:
return FileFount(ruv.alloc_fs(), 0, vat)
示例12: measureTimeTaken
def measureTimeTaken(self, f):
"""
Like m`f<-()`, but returns a promise for a pair
`[result, timeTaken :Double]` in seconds.
"""
from typhon.objects.collections.maps import EMPTY_MAP
vat = currentVat.get()
return vat.send(TimeMeasurer(f), RUN_0, [], EMPTY_MAP)
示例13: __init__
def __init__(self, code, frame, globals):
self.code = code
self.env = Environment(frame, globals, self.code.localSize(),
promote(self.code.maxDepth),
promote(self.code.maxHandlerDepth))
# For vat checkpointing.
from typhon.vats import currentVat
self.vat = currentVat.get()
示例14: makeStdOut
def makeStdOut():
vat = currentVat.get()
uv_loop = vat.uv_loop
tty = ruv.alloc_tty(uv_loop, 1, False)
# XXX works exactly as expected, including disabling most TTY signal
# generation
# ruv.TTYSetMode(tty, ruv.TTY_MODE_RAW)
return StreamDrain(ruv.rffi.cast(ruv.stream_tp, tty), vat)
示例15: makeReactorStats
def makeReactorStats():
"""
Compute some information about the reactor.
"""
# XXX what a hack
from typhon.vats import currentVat
loop = currentVat.get().uv_loop
return LoopStats(loop)