Пример #1
0
                try:
                    temp_username = [
                        i["UserName"] for i in itchat.get_friends()
                        if temp_nickname in (i["NickName"], i["RemarkName"])
                    ][0]
                except:
                    print("找不到指定联系人: {}".format(temp_nickname))
                    return
        # 执行!开头文本命令
        elif "!" == reply[0]:
            os.system(reply.strip("!"))
            return
        # 默认联系人操作
        else:
            temp_nickname = nickname
            temp_username = username

        if reply == "screen":
            itchat.send_image(toUserName=temp_username,
                              file_=get_new_file(Pictures))
        else:
            itchat.send_msg(reply, toUserName=temp_username)
        print("{} -> [{}]: {}".format(time.ctime()[11:19], temp_nickname,
                                      reply))


if __name__ == "__main__":
    threading._start_new_thread(auto_login, ())
    s = ThreadedServer(Wechat, port=50322, auto_register=False)
    s.start()
Пример #2
0
import rpyc
from rpyc import ThreadedServer
import sys


class Service1(rpyc.Service):
    def exposed_send_message(self, inp, port):
        c = rpyc.connect('localhost', port=port)
        c.root.receive_data(inp, port)

    def exposed_receive_data(self, message, port):
        print(message, port)


# inp=input('Enter the message\n')
# port=input('Enter the port you want to connect to')
# m=Service1()
# m.exposed_send_message(inp,port)
def print_data():
    inp = input('Enter the message')
    port = int(input('Enter the port you want to connect to'))


if __name__ == '__main__':

    t = ThreadedServer(Service1, port=int(sys.argv[1]))
    t.start()
 def run(self):
     server = ThreadedServer(ClipboardServer, port=18861)
     server.start()
Пример #4
0
import time

from rpyc import Service
from rpyc import ThreadedServer


class TimeService(Service):
    def exposed_get_time(self):
        return time.ctime()


if __name__ == "__main__":
    s = ThreadedServer(TimeService, port=18871)
    s.start()
Пример #5
0
		global k
		fn='mrjobfile%s'%uuid.uuid1()
		with open(os.path.expanduser('~')+'/Desktop/%s.py'%fn,'w') as mrjobfile:
			mrjobfile.write(content)
		mr_file_location=os.path.expanduser('~')+'/Desktop/'+fn+'.py'
		sub_folder=data_location+location
		file_list=list(os.listdir(sub_folder))
		
		for file in file_list:
			
			
		# # th_start(file_list)
			file_val=sub_folder+'/'+file
	
			k+=str(subprocess.getoutput('python %s %s'%(mr_file_location,file_val)))
		print(k)
		return k

		subprocess.getoutput('python %s %s'%(mr_file_location,location))

	



if __name__=='__main__':
	if not os.path.isdir(data_location):
		os.mkdir(data_location)
	t=ThreadedServer(DataService,port=port)
	t.start()

        return str(output, encoding='utf8')
        # return pyperclip.paste()

    def exposed_set_clipboard(self, content: str):
        import os
        print('set clipboard: ' + content)
        # QmetaObject
        QApplication.clipboard().setText(content, QClipboard.Clipboard)

        with open('/home/dusg/copy.txt', encoding='utf8', mode='w') as fp:
            fp.write(content)
        os.system('xclip -i ~/copy.txt')
        pyperclip.copy(content)


class MyThread(Thread):
    def run(self):
        server = ThreadedServer(ClipboardServer, port=18861)
        server.start()


if __name__ == '__main__':
    # server = MyThread()
    # server.start()

    app = QApplication(sys.argv)
    # app.exec()

    server = ThreadedServer(ClipboardServer, port=18861)
    server.start()
Пример #7
0
def start_daemon() -> None:
    t = ThreadedServer(GTD, port=Config.RPYC_PORT)
    t.start()
Пример #8
0
        for f in self.flights:
            if f.code == flightCode:
                return f

    def exposed_getAvailableFlights(self):
        return [flight.code for flight in self.flights]

    def exposed_bookAseat(self, flightCode):
        if flightCode in self.exposed_getAvailableFlights():
            foundFlight = self.getFlight(flightCode)
            foundFlight.bookASeat()
            return True
        return False

    def exposed_returnTicket(self, flightCode):
        if flightCode in self.exposed_getAvailableFlights():
            foundFlight = self.getFlight(flightCode)
            foundFlight.returnTicket()
            return True
        return False

    def exposed_viewFlightDetail(self, flightCode):
        if flightCode in self.exposed_getAvailableFlights():
            foundFlight = self.getFlight(flightCode)
            return foundFlight.viewDetail()
        return "There is no such flight"


if __name__ == '__main__':
    t = ThreadedServer(FlightService, port=port)
    t.start()
def server():
    t = ThreadedServer(CampoMinado, port=18861)
    t.start()
Пример #10
0
class RPC(rpyc.Service):
    def __init__(self,
                 identifier: str,
                 ip: str = "localhost",
                 port: int = 0,
                 server: "Server" = None,
                 *,
                 start_on_connect: bool = True,
                 self_parall: bool = True,
                 max_timeout: int = 600):
        print("RPC.__init__")
        self.ip = str(ip)
        self.port = int(port)

        self.server = server

        if (server is None): self._manager = Manager()
        else: self._manager = server._manager

        self._clients = External_list()
        self.__client_num = None

        self.client_start = []
        self.default_start = start_on_connect

        self.client_threads = self._manager.list()

        self.identifier = identifier

        self._socket = None

        self._run = []
        self._run_parall = []

        self._to_run = None

        self._args = []
        self._args_per_client = None
        self._args_parall = []

        self._result = External_list()

        self.max_timeout = max_timeout

    # Shared functions

    def __enter__(self):
        self.open()

    def __exit__(self, _, __, ___):
        pass

    def open(self):
        self._socket = ThreadedServer(self, hostname=self.ip, port=self.port)
        self._socket.SYNC_REQUEST_TIMEOUT = self.max_timeout

        self._socket.start()
        print(f"Open server ({self._socket}) in \n{self.ip}:{self.port}")

    def on_connect(self, conn):
        self._clients.append(conn)

        print(f"New client {len(self._clients)} connected")
        return super().on_connect(conn)

    def on_disconnect(self, conn):
        index = self._clients.index(conn)
        self._clients.pop(index)
        self._run.pop(index)
        self._run_parall.pop(index)
        self.client_threads.pop(index)

    def exposed_set_threads(self, threads: int):
        self.client_threads.append(threads)
        print(f"New client {len(self._clients)} has {threads} threads")

    def exposed_set_run(self, run_funct, run_parall=None):
        self._run.append(run_funct)
        self._run_parall.append(run_parall)

    def exposed_run_run(self, client: int = 0):
        if (self._run is None): return -1

        if (client >= 0):
            run = rpyc.async_(self._run[client])

            if (self._args_per_client is None):
                future = run(self.to_run, *self._args)
            else:
                future = run(self.to_run,
                             *self._args_per_client[self.__client_num])

            self._result.append(future)
        else:
            for num, run in enumerate(self._run):
                run = rpyc.async_(run)

                if (self._args_per_client is None):
                    future = run(self.to_run, *self._args)
                else:
                    future = run(self.to_run, *self._args_per_client[num])

                self._result.append(future)

        return future

    def exposed_run_parall(self):
        if (self._run_parall is None): return -1

        for num, run in enumerate(self._run_parall):
            print(run)
            run = rpyc.async_(run)  # In a var, as asked in the docs

            future = run(self.to_run, self.args_parall[num])
            self._result.append(future)

    def run(self, client: int = 0):
        self.exposed_run_run(client)

    def run_parall(self):
        self.exposed_run_parall()

    def result_async_values(self):
        result = []
        for num, result_end in enumerate(self._result):
            if (hasattr(result_end, "ready")):
                if (result_end.ready):
                    self._result[num] = result_end.value
                    result.append(result_end.value)
                continue

            result.append(result_end)

        return result

    def exposed_result_async(self):
        self.result_async_values()

    def divide_eq(self, iterable, n=None, fill=None):
        if (n is None): n = ceil(len(iterable) / sum(self.client_threads))
        return zip_longest(*[iter(iterable)] * n, fillvalue=fill)

    def divide_threads(self, iterable):
        prev = 0
        result = []
        for thread in self.client_threads:
            if (prev >= len(iterable)): break

            result.append(iterable[prev:prev + thread])
            prev += thread

        print(f"divide_threads : {result}")

        return result

    def _set_client_num(self):
        self.__client_num = self._clients.index(self)

    def get_to_run(self):
        return self._to_run

    def set_to_run(self, new_to_run):
        self._to_run = export_function(new_to_run)

    def get_args(self):
        return self._args

    def set_args(self, new_args):
        self._args = new_args

    def get_args_per_client(self):
        return self._args_per_client

    def set_args_per_client(self, new_args_pc):
        self._args_per_client = new_args_pc

    def get_args_parall(self):
        return self._args_parall

    def set_args_parall(self, new_args_parall):
        self._args_parall = new_args_parall

    to_run = property(get_to_run, set_to_run)
    args = property(get_args, set_args)
    args_per_client = property(get_args_per_client, set_args_per_client)
    args_parall = property(get_args_parall, set_args_parall)
    result = property(result_async_values)

    @staticmethod
    def flatten(l):
        result = []
        for level in l:
            if (isinstance(level, Iterable)):
                result.extend(level)
            else:
                result.append(level)
        return result
Пример #11
0
    def open(self):
        self._socket = ThreadedServer(self, hostname=self.ip, port=self.port)
        self._socket.SYNC_REQUEST_TIMEOUT = self.max_timeout

        self._socket.start()
        print(f"Open server ({self._socket}) in \n{self.ip}:{self.port}")
def start_function_service(func: Callable, port: int):
    s = ThreadedServer(GenericFunctionService(func), port=port)
    s.start()
Пример #13
0
def main():
    btr = ThreadedServer(BuildThreadRegisterService(),
                         port=config.resource_allocator.get('port', 18861))
    btr.start()