def __init__(self, parent, is_real_owner, id, operation_name,
                 operation_params):
        self.id = id

        self.started = False
        self.finished = False

        self.acknowledged = False

        self.name = "E" + str(self.id)
        self.operation_name = operation_name
        self.operation_params = operation_params

        self.parent = parent
        self.is_real_owner = is_real_owner
        self.ack = []

        self.sent_at = 0
        self.recv_at = 0
        self.should_execute_at = 0

        self.timestamp = [0 for x in range(NUM_OF_CHILDREN)]

        self.logger = getProcessLogger(self.parent.name + ":" + self.name)
        self.logger.setLevel(LOGGING_LEVEL)

        self.logger.info("created event:%s", self.name)
    def run(self):
        self.logger = getProcessLogger(self.name)
        self.logger.setLevel(LOGGING_LEVEL)
        self.logger.info("started process")

        t = Thread(target=self._run_threads)
        t.daemon = True
        t.start()
    def __init__(self, parent, process_index):
        self.queue = {}
        self.parent = parent
        self.current_time_stamp = [0 for x in range(NUM_OF_CHILDREN)]
        self.last_executed_stamp = [[0 for x in range(NUM_OF_CHILDREN)]]
        self.process_index = process_index

        self.logger = getProcessLogger(self.parent.name + ": ExecutionQueue")
        self.logger.setLevel(LOGGING_LEVEL)
    def __init__(self, id, address, all_address, clock_cycle):
        # id is 0 indexed

        self.id = id
        self.name = "P" + str(id)
        self.address = address

        self.all_address = all_address

        self.execution_queue = ExecutionQueue(self, id)

        self.started = False
        self.finished = False
        self.events = []
        self.latest_event = ''
        self.threads = []

        self.clock_cycle = clock_cycle
        self.timer = 0

        self.stop_executing = False
        self.logger = getProcessLogger('process')
        self.logger.setLevel(LOGGING_LEVEL)
        self.lock = threading.Lock()
 def __init__(self, name, filename):
     threading.Thread.__init__(self)
     self.name = name
     self.filename = filename
     self.logger = getProcessLogger(self.name)
from utils import getProcessLogger
import threading
import multiprocessing
import time

logger = getProcessLogger("process")

class Lock(object):
    def __init__(self):
        self.lock = False
    
    def acquire(self):
        while self.lock:
            pass

        self.lock = True
        return 
    
    def release(self):
        self.lock = False

lock = Lock()

class FileHandler(threading.Thread):
    lock = threading.Lock()

    def __init__(self, name, filename):
        threading.Thread.__init__(self)
        self.name = name
        self.filename = filename
        self.logger = getProcessLogger(self.name)
Exemple #7
0
import sys, os, socket, logging, math, random, time
from utils import getProcessLogger
from server_process import ServerProcess
from threading import Thread
from multiprocessing import Process
import signal
from constants import *

logger = getProcessLogger('server')
logger.setLevel(LOGGING_LEVEL)


class Server(object):
    def __init__(self, address):
        self.address = address
        self.socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.processes = []
        self.event_counter = 0

    def serve_infinitely(self):
        self.socket_server.bind(self.address)
        self.socket_server.listen(1)

        logger.info("starting server & listen to packets at %s", self.address)

        while True:
            connection, client_address = self.socket_server.accept()
            logger.debug("received a new connection with address %s",
                         client_address)
            try:
                while True:
Exemple #8
0
from utils import getProcessLogger
from process import FileHandler

logger = getProcessLogger("server")

FILENAME = "result.txt"

out_file = open(FILENAME, 'w')
out_file.close()

if __name__ == "__main__":
    processes = []
    for i in range(10):
        processes.append(FileHandler("P" + str(i), FILENAME))

    for p in processes:
        p.start()

    for p in processes:
        p.join()
import sys, os, socket, logging, math
import json
from utils import getProcessLogger
import time
from constants import *

logger = getProcessLogger('Client')
logger.setLevel(LOGGING_LEVEL)

address = ('localhost', 8080)

message_counter = 0

while message_counter < 10:
    message_counter += 1
    content = "message %s" % message_counter

    msg = {
        'type': 'operation',
        'operation_name': "save_content",
        'params': ["eventOutput.txt", content],
    }

    time.sleep(0.8)
    try:
        socket_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        socket_client.connect(address)
        socket_client.send(json.dumps(msg))
        logger.info("Sent message")
    except Exception as e:
        logger.info("Error")