chrisjbillington / zprocess

A collection of utilities for multiprocessing using zeromq.
BSD 2-Clause "Simplified" License
2 stars 5 forks source link

Update of processclass_remote_example.py #21

Open restelli opened 1 month ago

restelli commented 1 month ago

While running the example script processclass_remote_example.py I stumbled into the following error:

Traceback (most recent call last):
  File "C:\Users\arestell\OneDrive - University of Maryland\git\zprocess\zprocess\examples\processclass_remote_example.py", line 67, in <module>
    foo = Foo(process_tree, remote_process_client=remote_process_client)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\arestell\miniconda3\envs\synchro\Lib\site-packages\zprocess-0.1.dev561+gf367fda-py3.11.egg\zprocess\process_tree.py", line 1541, in __init__
    _Process.__init__(self, *args, **kwargs)
  File "C:\Users\arestell\miniconda3\envs\synchro\Lib\site-packages\zprocess-0.1.dev561+gf367fda-py3.11.egg\zprocess\process_tree.py", line 1007, in __init__
    raise RuntimeError(msg)
RuntimeError: Cannot start a remote process for a class defined in __main__. The remote process will not be able to import the required class as it will not know the import path. Either define the class in a different module importable on both systems, or use zprocess.Process directly, passing in subclass_fullname to specify the full import path.

Noticing that the class Process is (rightfully so!) performing some extra checks before opening a task in the remote server I modified the code by adding a remote package remote_example_package that the server can refer to.

After such modification the example runs without errors.

Here what I exactly do for running the example.

1) I start a remote server in a separate terminal by running:

python -m zprocess.remote -tui

2) In the current terminal I run:

python processclass_remote_example.py

A typical output is:

Note: script will not work without starting a zprocess.remote server.
See comments in the script for instructions
this is a running foo in process 20268
parent, got a response: hello yourself!
data is bar
foo, got a message: hello, foo!
here

however, as expected, due to the presence of some asynchronous tasks the messages can be written in a different order such as this:

Note: script will not work without starting a zprocess.remote server.
See comments in the script for instructions
parent, got a response: hello yourself!
this is a running foo in process 12804
data is bar
foo, got a message: hello, foo!
here

I hope that what I'm doing in the example represents a correct use case for zprocess.remote