def preloop(self): self.songs = list(ifiles(config.MUSICDIR, lambda f: f.endswith(".mp3"))) self.tests = dict( [i, TestProcess(i, strip_number(song), popencmd(song))] for i, song in enumerate(self.songs)) self.started_tests = set() self.do_show()
def asynchronous(): iters = map(count_gen, ifiles("/home/micheles", lambda f: f.endswith(".txt"))) for it in iters: # do not iterate on exhausted iterators it.next()
import test_pkg, doctest, os import sys from ms.file_utils import ifiles pkg = __import__("test_pkg") pkg_name = pkg.__name__ csd = os.path.dirname(test_pkg.__path__[0]) # current search directory os.chdir(csd) print "Testing package", pkg_name total_fail, total_ok = 0, 0 for f in ifiles(pkg_name, lambda f: f.endswith(".py"), abs_path=True): f = f[:-3].replace("/", ".") fail, ok = doctest.testmod(__import__(f, globals(), locals(), [f])) total_fail += fail total_ok += ok print "Failed %s, passed %s" % (total_fail, total_ok) # doctest.testmod(test_pkg) # only tests __init__ # doctest.run_docstring_examples(test_pkg, globals()) # idem
def synchronous(): for f in ifiles("/home/micheles", lambda f: f.endswith(".txt")): #print f, count(file(f)) count(file(f))
def threaded(): for f in ifiles("/home/micheles", lambda f: f.endswith(".txt")): threading.Thread(None, count, args=(file(f), )).start()
import os, random, threading from ms.file_utils import ifiles from ms.concurrency import Popen, locked PLAYER = "mplay32 /play /close".split() MUSICDIR = os.environ.get("HOMEPATH", os.environ["HOME"]) + "/Desktop/Music" songs = list(ifiles(MUSICDIR, lambda f : f.endswith(".mp3"))) def run(func, *args, **kw): threading.Thread(None, func, args=args, kwargs=kw).start() def gen_songs(): for i in range(2): yield random.choice(songs) def play(song): return Popen(PLAYER + [song]) @locked def play_many(user): for song in gen_songs(): print user, song player = play(song) player.wait() if __name__ == "__main__": run(play_many, "user1") run(play_many, "user2") run(play_many, "user3")
from ms.file_utils import ifiles import os def gen(fname): for line in file(fname): yield line def multi_iter(iters): iters = list(iters) # to avoid side effects while iters: for it in iters: try: yield it.next() except StopIteration: iters.remove(it) ci = multi_iter( gen(f) for f in ifiles("/home/micheles/md/python/Timing", lambda f: f.endswith(".txt"))) for line in ci: print line,
from ms.file_utils import ifiles import os def gen(fname): for line in file(fname): yield line def multi_iter(iters): iters = list(iters) # to avoid side effects while iters: for it in iters: try: yield it.next() except StopIteration: iters.remove(it) ci = multi_iter(gen(f) for f in ifiles("/home/micheles/md/python/Timing", lambda f: f.endswith(".txt"))) for line in ci: print line,
def preloop(self): self.songs = list(ifiles(config.MUSICDIR, lambda f: f.endswith(".mp3"))) self.tests = dict([i, TestProcess(i, strip_number(song), popencmd(song))] for i, song in enumerate(self.songs)) self.started_tests = set() self.do_show()
def threaded(): for f in ifiles("/home/micheles", lambda f: f.endswith(".txt")): threading.Thread(None, count, args=(file(f),)).start()
def synchronous(): for f in ifiles("/home/micheles", lambda f: f.endswith(".txt")): # print f, count(file(f)) count(file(f))