1

I was trying to use the following piece of code for reading from the console indefinitely:

def read_console(hub):
    while True:
        text = input("write stuff")
        if text == 'y':
            hub.server.invoke('Say', 'hello')
        print (text)

connection = Connection('https://1234.net/signalr', session=None)
hub = connection.register_hub('echo')

read_console_process = multiprocessing.Process(target=read_console, args=(hub,))
read_console_process.start()

However I ran into a pickle issue and decided to try using pathos, I tried the following but I'm receiving the error - zip argument #1 must support iteration:

def main():
    connection = Connection('https://1234.net/signalr', session=None)
    hub = connection.register_hub('echo')

    executor = ProcessingPool()
    executor.map(read_console, hub)
TomSelleck
  • 6,706
  • 22
  • 82
  • 151
  • You most likely should either make the connection in the read_console function. Or use a manager to proxy the hub. – Dan D. Feb 05 '19 at 01:33
  • Thanks for the reply - this is sort of new to me, could you provide an example of what I should try? – TomSelleck Feb 05 '19 at 09:51

1 Answers1

1

I'm the pathos author. A ProcessingPool is a pool of Process objects. I think you are looking for either multiprocess.Process, or pathos.helpers.mp.Process, which are actually both the same object.

Mike McKerns
  • 33,715
  • 8
  • 119
  • 139
  • That's great. But this doesn't answer the question. The asker is attempting to pass an object that has a socket over to a child. – Dan D. Feb 05 '19 at 13:54
  • Yes, @DanD., the answer is to use the object I suggest which has the identical interface to the `Process` object he wanted to use initially. Were he to use a `ProcessPool`, he'd have to pass a list of sockets, as the intent is for the pool to manage multiple `Process` objects under the covers. – Mike McKerns Feb 05 '19 at 17:56
  • Also, the OP doesn't really ask a question... so I took it as interpret it how you like to get the OP to a working solution. – Mike McKerns Feb 05 '19 at 17:58
  • Thanks for taking the time to reply - I won't have a chance to try it tonight but I'll be sure to give it a go tomorrow. My question was exactly that - how do I pass my object (which contains a socket) to another process - as I would have using the standard multiprocessing library... – TomSelleck Feb 05 '19 at 23:35
  • It seems this is not up-to-date anymore. What should be used nowadays? – Make42 Jun 19 '23 at 13:49
  • @Make42: I'm not sure what you mean. What's "this"? `pathos` and `multiprocess` are released regularly, and the answer is still relevant. – Mike McKerns Jun 20 '23 at 23:15
  • @MikeMcKerns: I have pathos 0.3.0 installed and PyCharm tells me with `import pathos.helpers.mp.Process` that `mp` does not exist, and in `import multiprocess.Process` that `Process` does not exist. – Make42 Jun 21 '23 at 10:24
  • That's true. You'll need to import the module first. Try `from pathos.helpers import mp` or `import multiprocess as mp`, and then you should have the same module with `mp.Process`. – Mike McKerns Jun 21 '23 at 18:06