def handle(self):
     print "Thread1 started\n"
     while 1:
         try:
             self.data = self.request.recv(1024)
             sh.temperatureSet(self.data)
         except socket.error, msg:
             self.request.close()
             break
 def handle(self):
     print "Thread2 started\n"
     global invoker
     while 1:
         try:
             self.data = self.request.recv(1024)
             if self.data == "False":
                 sh.setTheAlarm(False)
             else:
                 sh.setTheAlarm(True)
         except socket.error, msg:
             self.request.close()
             break
    def handle(self):
        print "Thread3 started\n"

        while 1:
            try:
                stringToSend = "<temp>" + str(sh.temperatureGet()) + "</temp>\n"
                self.request.sendall(stringToSend)
                stringToSend = "<alarm>" + str(sh.readTheAlarm()) + "</alarm>\n"
                self.request.sendall(stringToSend)
            except socket.error, msg:
                self.request.close()
                break
            time.sleep(1)
Exemplo n.º 4
0
def main(*args, shared_memory_conn=None, **kwargs):
    '''Prints the shared memory value to the screen repeatedly'''

    #The connection to the parent script is automatically passed in as shared_memory_conn

    smo = SharedMemory.SharedMemoryObject(
        'msg', shared_memory_conn)  #Initiates the SharedMemory object locally

    print('TestChild has initiated')
    sys.stdout.flush()

    start = time.time()
    while time.time() - start < 2.5:
        #gets the loval value for the smo Shared memory object
        print("Variable 'smo' has value '{}' in TestChild".format(smo.Get()))
        sys.stdout.flush()

        time.sleep(0.05)
Exemplo n.º 5
0
"""
Created on Sat Sep  7 10:38:13 2019

@author: fb
"""
import SharedMemory
import time
import TestChild
import sys

if __name__ == "__main__":
    '''Starts TestChild.main as a subprocess and initiates a SharedMemory connection with it. The updates the 
   SharedMemory object's value repeatedly for 3 seconds'''
    #Spawns a subprocess (equivaent to multiprocess.Process()) and opens a connection with it
    #via multiprocess.Pipe()
    parent_conn = SharedMemory.SharedMemoryProcess(target=TestChild.main,
                                                   daemon=True)

    msg = 0
    smo = SharedMemory.SharedMemoryObject(
        'msg', parent_conn)  #locally initiates the SgaredMemory object

    print('TestParent has initiated')
    sys.stdout.flush()

    start = time.time()
    while time.time() - start < 3:
        time.sleep(0.1)
        msg += 1

        print('TestParent is updating smo to {}'.format(msg))
        sys.stdout.flush()
 def testAlarmGet(self):
     self.assertFalse(sm.readTheAlarm())
 def testTemperatureGet(self):
     self.assertEqual(0,sm.temperatureGet())