예제 #1
0
#parsed

from pymoult.highlevel.managers import ThreadedManager
import sys

main = sys.modules["__main__"]

manager = ThreadedManager()
manager.start()


예제 #2
0
    def display(self):
        log(0, "An item named " + self.name + " of color " + self.color)

    def change(self, color):
        self.color = color


def main():
    items = [
        Item("apple", "red"),
        Item("banana", "yellow"),
        Item("mango", "green")
    ]
    for x in range(8):
        for i in items:
            i.display()
        time.sleep(1)


thread = threading.Thread(target=main, name="app")
manager = ThreadedManager(name='global', threads=[thread])
manager.start()
thread.start()
listener = Listener()
listener.start()

thread.join()
manager.stop()
listener.stop()
예제 #3
0
#parsed

from pymoult.highlevel.updates import SafeRedefineUpdate
from pymoult.highlevel.managers import ThreadedManager
import sys

main = sys.modules["__main__"]


def hello_v2():
    print("Hello Dave")


manager = ThreadedManager()
manager.start()
update = SafeRedefineUpdate(main, main.hello, hello_v2)

manager.add_update(update)
예제 #4
0
        self.direction = "right"
    sys.modules["__main__"].gprint("The "+self.color+" train is changing direction to "+self.direction)

def getTrainThreads():
    def f(t):
        if t.name in ["blue_train","red_train","green_train","purple_train","orange_train","white_train"]:
            return True
        else:
            return False
           
    #We can get all the train through the enumerate method
    threads = list(filter(f,threading.enumerate()))
    return threads


manager = ThreadedManager(name="GlobalManager",threads=getTrainThreads())
manager.start()

class TrainUpdate(Update):
    def wait_alterability(self):
        return True
    def apply(self):
        for train in self.manager.threads:
            train.direction = "right"
        addMethodToClass(main.Train,"__int__",newTrainInit)
        addMethodToClass(main.Train,"switch_direction",switch_direction)
    def cleanup(self):
        print("Trains sucessfully updated")

manager.add_update(TrainUpdate(name="Trains"))
예제 #5
0
#/usr/bin/python-dsu3

from pymoult.highlevel.managers import ThreadedManager
from pymoult.highlevel.listener import Listener
import time


def tic():
    print("tic")


def tac():
    print("tac")


def main():
    while True:
        time.sleep(1)
        tic()
        time.sleep(1)
        tac()


manager = ThreadedManager(name='Manager')
manager.start()
listener = Listener()
listener.start()
main()
예제 #6
0
#Testing failed alterability

from pymoult.highlevel.managers import ThreadedManager
from pymoult.threads import DSU_Thread
from pymoult.highlevel.listener import Listener,log
import time
import threading
import sys
  
def func_v1():
    log(0,"v1")

def main():
    for x in range(8):
        time.sleep(1)
        func_v1()


thread = DSU_Thread(target=main,name="app")
thread.start()
manager = ThreadedManager(name="pymoult",threads=[thread])
manager.start()

listener = Listener()
listener.start()

thread.join()
manager.stop()
listener.stop()

예제 #7
0
    elif comm.startswith("login "):
        do_login(comm.lstrip("login").strip())
    elif comm.startswith("logout"):
        do_logout(comm.lstrip("logout").strip())
    elif comm.startswith("register "):
        do_register(comm.lstrip("register").strip())


def main_loop():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((hostname, port))
    s.listen(max_connections)
    while True:
        #This is a safe point for updating
        staticUpdatePoint()
        conn, addr = s.accept()
        data = conn.recv(max_data_length)
        do_command(data.decode("ascii"))
        data = ""
        conn.close()


if __name__ == "__main__":
    listener = Listener()
    listener.start()
    main_thread = DSU_Thread(name="main thread", target=main_loop)
    print("Starting server")
    main_thread.start()
    manager = ThreadedManager(threads=[main_thread])
    manager.start()
예제 #8
0
        #Create a http server listening on localhost port 8080
        #The server will use the self.Handler class to handle the clients requests
        httpd = HTTPServer(("", 8080), self.Handler)
        while True:
            staticUpdatePoint()
            httpd.handle_request()


def main():
    p1 = Page("banana", "Banana!",
              "A nice fruit. Allways bring one to parties")
    p2 = Page("coconut", "Coconut", "A fine coconut")
    p3 = Page("hello", "Hello World!", "Hello!")
    pages = [p1, p2, p3]
    ws = WebServer(pages)
    ws.run()


#Listener
listener = Listener()
listener.start()

#Setup the main thread
main_thread = DSU_Thread(target=main)

#Eager update manager for the Page class
manager = ThreadedManager(name="global manager", threads=[main_thread])
manager.start()

main_thread.start()
예제 #9
0
    global shared
    shared_lock.acquire()
    time.sleep(1)
    shared = random.randint(0, 10)
    shared_lock.release()


def reader_f():
    while True:
        time.sleep(1)
        read_shared()


def writer_f():
    while True:
        time.sleep(1.5)
        write_shared()


writer = threading.Thread(target=writer_f)
writer.start()
reader = threading.Thread(target=reader_f)
reader.start()

manager = ThreadedManager(name="Manager", threads=[reader, writer])
manager.set_sleepTime(0.5)
manager.start()

listener = Listener()
listener.start()
예제 #10
0
    if l[0] == "all":
        for s in main.sites:
            if check_access(s):
                print(s)
    else:
        site = main.find_name_in_list(l[1],main.sites)
        if l[0] == "site":
            if site and check_access(site):
                print(site)
        elif l[0] == "page":
            if site and site.get_page(l[2]) and check_access(site):
                print(site.get_page(l[2]))


#Start the managers
account_manager = ThreadedManager(threads=[main.main_thread])
account_manager.start()
site_manager = ThreadedManager(threads=[main.main_thread])
site_manager.start()
functions_manager = ThreadedManager(threads=[main.main_thread])
functions_manager.start()


def transformer_site(site):
    site.owner = None

def transformer_account(account):
    account.friends=[]

site_update = LazyConversionUpdate(main.Site,SiteV2,transformer_site,None)
account_update = LazyConversionUpdate(main.Account,AccountV2,transformer_account,None)