diff --git a/zprocess/examples/processclass_remote_example.py b/zprocess/examples/processclass_remote_example.py index e4f8a2c..08093e5 100644 --- a/zprocess/examples/processclass_remote_example.py +++ b/zprocess/examples/processclass_remote_example.py @@ -13,7 +13,7 @@ from __future__ import print_function from zprocess import Process, ProcessTree -import os + """Before running this example program, you need to start a remote process server. Start one in a terminal with: @@ -21,6 +21,8 @@ python -m zprocess.remote -tui then run this script. +The example package 'remote_example_package' with the class 'Fo' must be present in +the folder from where zprocess.remote is run. To test across multiple machines, set REMOTE_HOST below to the hostname of the other computer, and generate a shared secret and save it to file with: @@ -47,16 +49,20 @@ shared_secret = None +# The zprocess.remote server will remotely execute the Foo process below. +""" class Foo(Process): def run(self, data): - print('this is a running foo in process %d' % os.getpid()) + print('this is a running foo in process %d ' % os.getpid()) print('data is', data) message = self.from_parent.get() print('foo, got a message:', message) self.to_parent.put('hello yourself!') import time time.sleep(1) +""" +REMOTE_CLASS = 'remote_example_package.Foo' # This __main__ check is important to stop the same code executing again in the child: if __name__ == '__main__': @@ -64,7 +70,9 @@ def run(self, data): print("See comments in the script for instructions") process_tree = ProcessTree(shared_secret) remote_process_client = process_tree.remote_process_client(REMOTE_HOST) - foo = Foo(process_tree, remote_process_client=remote_process_client) + foo = Process(process_tree, + remote_process_client=remote_process_client, + subclass_fullname=REMOTE_CLASS) to_child, from_child = foo.start('bar') to_child.put('hello, foo!') response = from_child.get() diff --git a/zprocess/examples/remote_example_package/__init__.py b/zprocess/examples/remote_example_package/__init__.py new file mode 100644 index 0000000..4f5a3d0 --- /dev/null +++ b/zprocess/examples/remote_example_package/__init__.py @@ -0,0 +1,26 @@ +##################################################################### +# # +# processclass_example.py # +# # +# Copyright 2024, Chris Billington # +# # +# This file is part of the zprocess project (see # +# https://bitbucket.org/cbillington/zprocess) and is licensed under # +# the Simplified BSD License. See the license.txt file in the root # +# of the project for the full license. # +# # +##################################################################### + +from __future__ import print_function +from zprocess import Process +import os + +class Foo(Process): + def run(self, data): + print('this is a running foo in process %d ' % os.getpid()) + print('data is', data) + message = self.from_parent.get() + print('foo, got a message:', message) + self.to_parent.put('hello yourself!') + import time + time.sleep(1)