Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of processclass_remote_example.py #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions zprocess/examples/processclass_remote_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@

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:

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:
Expand All @@ -47,24 +49,30 @@
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__':
print("Note: script wil not work without starting a zprocess.remote server.")
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()
Expand Down
26 changes: 26 additions & 0 deletions zprocess/examples/remote_example_package/__init__.py
Original file line number Diff line number Diff line change
@@ -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)