本文整理汇总了Python中stackless.schedule函数的典型用法代码示例。如果您正苦于以下问题:Python schedule函数的具体用法?Python schedule怎么用?Python schedule使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了schedule函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
def run(self, timeout = 100):
n = c_ulong()
key = c_ulong()
pol = POINTER(OVERLAPPED)()
while 1:
key.value = 0
r = GetQueuedCompletionStatus( self.hiocp, byref(n), byref(key), byref(pol), c_ulong(timeout) )
print r, pol, n, key, GetLastError()
if r == 0:
if( key.value > 0 ):
t = pol.contents.Type
obj = self.objmap[key.value]
if t == 4:
obj.recv_ch.send( 0 )
self.close_socket(obj)
SL.schedule()
continue
# 1 recv, 2 send, 3 accept, 4 connect, 5 read 6 write
t = pol.contents.Type
sock = self.objmap[key.value]
if t == 1:
if sock.is_server:
sock.recv_ch.send( 1 )
else:
sock.recv_ch.send( n.value )
elif t == 2:
sock.send_ch.send( n.value )
elif t == 3:
sock.recv_ch.send( 1 )
elif t == 4:
sock.recv_ch.send(r)
elif t == 5:
sock.read_ch.send(n.value)
SL.schedule()
开发者ID:bahamut8348,项目名称:xkcode,代码行数:35,代码来源:iocp.py
示例2: test_except
def test_except(self):
rlist = []
def f():
rlist.append('f')
return 1/0
def g():
rlist.append('bg')
stackless.schedule()
rlist.append('ag')
def h():
rlist.append('bh')
stackless.schedule()
rlist.append('ah')
tg = stackless.tasklet(g)()
tf = stackless.tasklet(f)()
th = stackless.tasklet(h)()
try:
stackless.run()
# cheating, can't test for ZeroDivisionError
except Exception as e:
rlist.append('E')
stackless.schedule()
stackless.schedule()
assert rlist == "bg f E bh ag ah".split()
开发者ID:Qointum,项目名称:pypy,代码行数:29,代码来源:test_stackless.py
示例3: test_simple_channel
def test_simple_channel(self):
output = []
def print_(*args):
output.append(args)
def Sending(channel):
print_("sending")
channel.send("foo")
def Receiving(channel):
print_("receiving")
print_(channel.receive())
ch=stackless.channel()
task=stackless.tasklet(Sending)(ch)
# Note: the argument, schedule is taking is the value,
# schedule returns, not the task that runs next
#stackless.schedule(task)
stackless.schedule()
task2=stackless.tasklet(Receiving)(ch)
#stackless.schedule(task2)
stackless.schedule()
stackless.run()
assert output == [('sending',), ('receiving',), ('foo',)]
开发者ID:Qointum,项目名称:pypy,代码行数:29,代码来源:test_stackless.py
示例4: cap_thread
def cap_thread():
for t, data in cap:
d = data[54:]
pos = d.find("\n")
if pos > 0:
print d[:pos]
SL.schedule( )
开发者ID:bahamut8348,项目名称:xkcode,代码行数:7,代码来源:sg.py
示例5: sleep
def sleep(self, delay=0):
"""Suspend the active tasklet for a specified amount of seconds
If delay is zero (default) then the tasklet just blocks.
Returns seconds passed since sleep was called.
"""
startTime = time.clock()
when = startTime + delay
if delay:
try:
try:
chn = self.chnPool.pop()
except IndexError:
chn = stackless.channel()
# could also allocate more channels for chnPool
self.sleepers.append((when, chn))
chn.receive()
finally:
self.chnPool.append(chn)
else:
stackless.schedule()
return time.clock() - startTime
开发者ID:breezechen,项目名称:stacklessexamples,代码行数:25,代码来源:uthread.py
示例6: testSendInsert
def testSendInsert(self):
channel_obj = stackless.channel()
self.assertEqual(None, channel_obj.queue)
tasklet1 = stackless.tasklet(lambda: 1 / 0)()
tasklet2 = stackless.tasklet(channel_obj.receive)()
tasklet2.run()
self.assertRaisesStr(
RuntimeError, 'You cannot remove a blocked tasklet.',
tasklet2.remove)
# channel_obj.send inserts tasklet2 after current, and since tasklet1 was
# after current, the insertion runs tasklet1 eventually, which triggers
# the ZeroDivisionError, propagated to current (== main).
self.assertRaises(ZeroDivisionError, channel_obj.send, 0)
self.assertEqual(1, stackless.getruncount())
self.assertEqual(None, channel_obj.queue)
channel_obj.preference = 1 # Prefer the sender.
tasklet1 = stackless.tasklet(lambda: 1 / 0)()
tasklet2 = stackless.tasklet(channel_obj.receive)()
self.assertEqual(False, tasklet2.blocked)
self.assertEqual(True, tasklet2.scheduled)
tasklet2.run()
self.assertEqual(True, tasklet2.blocked)
self.assertEqual(True, tasklet2.scheduled)
self.assertEqual(tasklet1, stackless.getcurrent().next)
self.assertEqual(None, channel_obj.send(0))
self.assertEqual(tasklet1, stackless.getcurrent().next)
self.assertEqual(tasklet2, stackless.current.prev)
tasklet1.remove()
stackless.schedule()
开发者ID:breezechen,项目名称:syncless,代码行数:30,代码来源:stackless_test.py
示例7: run
def run(self, timeout = 100):
n = c_ulong()
key = c_ulong()
pol = POINTER(OVERLAPPED)()
while 1:
key.value = 0
r = GetQueuedCompletionStatus( self.hiocp, byref(n), byref(key), byref(pol), timeout )
print r, pol, n, key, GetLastError()
if r == 0:
if( key.value > 0 ):
t = pol.contents.Type
sock = self.sockmap[key.value]
if t == 3:
sock.read_ch.send(0)
self.close_socket(key.value)
SL.schedule()
continue
t = pol.contents.Type
sock = self.sockmap[key.value]
if t == 1:
if sock.is_server:
sock.read_ch.send( 1 )
else:
sock.read_ch.send( n.value )
elif t == 2:
sock.write_ch.send( n.value )
elif t == 3:
sock.read_ch.send( 1 )
SL.schedule()
开发者ID:bahamut8348,项目名称:xkcode,代码行数:29,代码来源:test2.py
示例8: nodeFunction
def nodeFunction(self, myID, instrChannel,
myChannel, lnChannel, rnChannel):
print myID
myState = False
while True:
todo = instrChannel.receive()
stackless.schedule()
if todo[0] == 'ret':
myChannel.send(myState)
elif todo[0] == 'set':
if todo[1] == None:
myState = myChannel.receive()
else:
myState = todo[1]
elif todo[0] == 'shiftR':
if myID % 2 == 0:
rnChannel.send(myState)
myState = myChannel.receive()
else:
tmp = myChannel.receive()
rnChannel.send(myState)
myState = tmp
stackless.schedule()
开发者ID:a8ksh4,项目名称:junk,代码行数:25,代码来源:dingdong.py
示例9: recv
def recv(self, size):
start = time()
while True:
try:
return self.ssl.recv(size)
except (WantReadError, WantWriteError):
schedule()
if time() - start > 3:
raise SocketTimeout('time out')
continue
except SysCallError, e:
if e.args == (-1, 'Unexpected EOF'):
return ''
raise SocketError(e.args[0])
except SSLError, e:
try:
thirdarg = e.args[0][0][2]
except IndexError:
raise e
else:
if thirdarg == 'first num too large':
schedule()
if time() - start > 3:
raise SocketTimeout('time out')
continue
raise
开发者ID:ZoomQuiet,项目名称:eurasia,代码行数:33,代码来源:socket2.py
示例10: runAction
def runAction(self):
# Here we define the main action, a repetition of the function self.action()
while self.running:
# Runs the action
self.action()
# Give other tasklets its turn
stackless.schedule()
开发者ID:kotejante,项目名称:sample-psp-game,代码行数:7,代码来源:script.py
示例11: MainLoop
def MainLoop(self):
t=time.time()
while self.running:
self.Tick()
self.DrawFrame()
T=t
self.lastframetime=time.time()-t
t=time.time()
#FIXED FRAME RATE
#block until the difference is made up
while time.time()-t < (1.0/30)-self.lastframetime-(10.0/6000):
pass
#import agl
#vsync=1
#swap = c_long(int(vsync))
#_agl_context=agl.aglGetCurrentContext()
#agl.aglSetInteger(_agl_context, agl.AGL_SWAP_INTERVAL, byref(swap))
self.lastframetime=time.time()-T
t=time.time()
gfx.SwapBuffers()
self.ProcessEvents()
#print "mainloop schedule"
stackless.schedule()
开发者ID:retrogradeorbit,项目名称:Pigo,代码行数:27,代码来源:App.py
示例12: poll
def poll(self, timeout=1):
while self.running and (self.overlappedByID or self._sleepers):
self._check_sleepers()
numBytes = DWORD()
completionKey = c_ulong()
ovp = POINTER(OVERLAPPED)()
ret = GetQueuedCompletionStatus(self.handle, byref(numBytes),
byref(completionKey), byref(ovp),
timeout)
if not ovp and ret == 0:
if GetLastError() == WAIT_TIMEOUT:
stackless.schedule()
continue
if ovp.contents.taskletID in self.overlappedByID:
#print ovp.contents.taskletID, " tasklet ID IN pool"
c = self.overlappedByID[ovp.contents.taskletID]
else:
#print ovp.contents.taskletID, " tasklet ID NOT in pool"
continue
#print "sending data back to channel in ID", ovp.contents.taskletID
c.send(numBytes)
#print "sent data to channel in ID", ovp.contents.taskletID, numBytes
self.UnregisterChannelObject(ovp.contents.taskletID)
self.running = False
开发者ID:breezechen,项目名称:stacklessexamples,代码行数:29,代码来源:stacklessfileIOCP.py
示例13: die
def die(self):
self.actor.send_message(self.actor, 'You have just died!')
self.actor.set_room('Test/Death/Death Room')
stackless.schedule()
self.actor.room.broadcast(
'%s falls to the ground, dead!' % self.actor.action_description,
self.actor)
开发者ID:mrgaaron,项目名称:Drake,代码行数:7,代码来源:body.py
示例14: startwork
def startwork( f ):
while 1:
buf = f.recv(10)
print `buf`
f.send( buf )
SL.schedule()
开发者ID:bahamut8348,项目名称:xkcode,代码行数:7,代码来源:iocp.py
示例15: worker
def worker(ch, sec, message):
while True:
sec.send(ch)
ch.receive()
print message
stackless.schedule()
sleep.Sleep(random.randint(0, 3))
开发者ID:bzimmer,项目名称:izoard,代码行数:7,代码来源:santa.py
示例16: send_stackless_activity
def send_stackless_activity(f, *a, **kw):
""" This allows to launch a function in an async way. A Deferred is returned """
d= defer.Deferred()
t= stackless.tasklet(_stackless_thread_channel.send)
t((d, f, a, kw))
stackless.schedule()
return d
开发者ID:efphe,项目名称:efphe,代码行数:7,代码来源:twiless.py
示例17: testRunnablesOrderAtKill
def testRunnablesOrderAtKill(self):
def Safe(items):
try:
items.append('start')
stackless.schedule()
except ValueError:
items.append('caught')
stackless.schedule()
tasklet1 = stackless.tasklet(lambda: 1 / 0)()
items = []
tasklet2 = stackless.tasklet(Safe)(items)
tasklet2.run()
assert 'start' == ','.join(items)
tasklet3 = stackless.tasklet(lambda: 1 / 0)()
tasklet2.remove()
tasklet2.remove()
tasklet2.raise_exception(ValueError)
assert 'start,caught' == ','.join(items)
assert tasklet1.alive
assert not tasklet2.alive
assert tasklet3.alive
tasklet1.remove()
tasklet1.kill() # Don't run tasklet3.
tasklet3.kill()
tasklet2.kill()
开发者ID:breezechen,项目名称:syncless,代码行数:26,代码来源:stackless_test.py
示例18: __getitem__
def __getitem__(self, key):
if key in self.deleted:
raise KeyError(key)
try:
return self.cache[key]
except KeyError:
pass
while not self.cache_invalid_lock.acquire(0):
schedule()
try:
if key in self.invalid:
raise ReadConflictError(key)
e = channel()
self.queue.put((e, dbmget, (self.db, key), {}))
errno, e = e.receive()
if errno != 0:
raise e
o = loads(e)
self.cache[key] = o
finally:
self.cache_invalid_lock.release()
return o
开发者ID:noscripter,项目名称:eurasia,代码行数:27,代码来源:shelve2.py
示例19: run
def run(self):
while 1:
Url.run(self)
secondsToWait = 3.0
endTime = time.time() + secondsToWait
while time.time() < endTime:
stackless.schedule()
开发者ID:thanos,项目名称:taxy,代码行数:7,代码来源:stackless_core.py
示例20: stackless_task
def stackless_task():
global exit_now
while not exit_now:
try:
request = stackless_queue.get(block=True, timeout=0.01)
except Queue.Empty:
stackless.schedule()
continue
seq, method, args, kwargs = request
#print >> sys.__stderr__, "stackless_task", globals(), __main__.__dict__
#print >> sys.__stderr__, method, args, kwargs
#print >> sys.__stderr__
type, value, tb = sys.exc_info()
try:
ret = method(*args, **kwargs)
except:
try:
if hasattr(method, "im_self"):
method.im_self.idb.gui.interaction(None, None)
print_exception()
rpc.response_queue.put((seq, None))
except:
# Link didn't work, print same exception to __stderr__
traceback.print_exception(type, value, tb, file=sys.__stderr__)
exit()
else:
continue
rpc.response_queue.put((seq, ret))
stackless.schedule()
exit_now = getattr(RemoteDebugger.__main__, "exit_now", False)
开发者ID:lebauce,项目名称:artub,代码行数:31,代码来源:run.py
注:本文中的stackless.schedule函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论