##language:zh #pragma section-numbers off ##含有章节索引导航的 ZPyUG 文章通用模板 <> ## 默许导航,请保留 <> = StacklessPy的Sleep 方式 = ##startInc {{{ @googlegroups.com> date Wed, Feb 4, 2009 at 21:33 subject [eurasia-users] Re: StopIteration: the main tasklet is receiving without a sender available. }}} == eruaisa的 == 欢迎进入 Stackless Python 的世界! {{{#!python import sqlite3, sha from time import time from random import random from sqlite3 import IntegrityError from stackless import tasklet, schedule, channel def sleep(sec): c = channel() while True: uid = sha.new('%s' % random()).hexdigest() try: cursor.execute( 'INSERT INTO hypnus VALUES (?, ?)', (uid, time() + sec) ) break except IntegrityError: continue channels[uid] = c c.receive() def tasklets(): while True: now = time() l = cursor.execute( 'SELECT id FROM hypnus WHERE timeout>]