WolframClientForPython: SocketAborted problem
My Environment: Activated MMA 12.0 works correctly on my Ubuntu 16.04 system.
I install WolframClient with following code:
pip install wolframclient -i https://pypi.doubanio.com/simple
Then I execute following codes in python 3.6.10:
from wolframclient.evaluation import WolframLanguageSession
sess = WolframLanguageSession(path)
sess.start()
where, the path I try different values like the result of :
$ which WolframKernel
in my case, it’s ‘/usr/local/bin/WolframKernel’ , or the output of
First@$CommandLine
which is ‘/usr/local/Wolfram/Mathematica/12.0/SystemFiles/Kernel/Binaries/Linux-x86-64/WolframKernel’ or use this path ‘/usr/local/Wolfram/Mathematica/12.0/Executables/WolframKernel’ which is default path of WolframLanguageSession().
Then errors are vary when I choose different paths, but can be concluded into 2 types.
- When path = ‘/usr/local/Wolfram/Mathematica/12.0/SystemFiles/Kernel/Binaries/Linux-x86-64/WolframKernel’ , it immediately returns following errors info:
Socket exception: Socket operation aborted.
Failed to start.
---------------------------------------------------------------------------
SocketAborted Traceback (most recent call last)
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py in _kernel_start(self)
436 timeout=self.get_parameter("STARTUP_TIMEOUT"),
--> 437 abort_event=_StartEvent(self.kernel_proc, self.trigger_termination_requested),
438 )
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/zmqsocket.py in recv_abortable(socket, timeout, abort_check_period, abort_event, **kwargs)
49 if abort_event.is_set():
---> 50 raise SocketAborted("Socket operation aborted.")
51 if timeout and (time.perf_counter() - start > timeout):
SocketAborted: Socket operation aborted.
During handling of the above exception, another exception occurred:
WolframKernelException Traceback (most recent call last)
<ipython-input-4-84c234a8332d> in <module>
----> 1 sess.start()
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/localsession.py in start(self, block, timeout)
155 self.terminate()
156 finally:
--> 157 raise e
158
159 def start_future(self):
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/localsession.py in start(self, block, timeout)
150 future = self.start_future()
151 if future and block:
--> 152 future.result(timeout=timeout)
153 except Exception as e:
154 try:
~/anaconda3/envs/detectron2/lib/python3.6/concurrent/futures/_base.py in result(self, timeout)
430 raise CancelledError()
431 elif self._state == FINISHED:
--> 432 return self.__get_result()
433 else:
434 raise TimeoutError()
~/anaconda3/envs/detectron2/lib/python3.6/concurrent/futures/_base.py in __get_result(self)
382 def __get_result(self):
383 if self._exception:
--> 384 raise self._exception
385 else:
386 return self._result
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py in run(self)
525 # Kernel start requested.
526 if payload is self.START:
--> 527 self._safe_kernel_start()
528 future.set_result(True)
529 future = None
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py in _safe_kernel_start(self)
364 self._kernel_terminate()
365 finally:
--> 366 raise e
367
368 _KERNEL_OK = b"OK"
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py in _safe_kernel_start(self)
358 """ Start a kernel. If something went wrong, clean-up resources that may have been created. """
359 try:
--> 360 self._kernel_start()
361 except Exception as e:
362 logger.warning("Failed to start.")
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py in _kernel_start(self)
454 logger.warning("Socket exception: %s", se)
455 raise WolframKernelException(
--> 456 "Failed to communicate with kernel: %s." % self.kernel
457 )
458
WolframKernelException: Failed to communicate with kernel: [path].
- When path != ‘/usr/local/Wolfram/Mathematica/12.0/SystemFiles/Kernel/Binaries/Linux-x86-64/WolframKernel’, it will wait for several seconds and return following errors:
Socket exception: Failed to read any message from socket tcp://127.0.0.1:39963 after 20.1 seconds and 200 retries.
Failed to start.
---------------------------------------------------------------------------
SocketOperationTimeout Traceback (most recent call last)
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py in _kernel_start(self)
436 timeout=self.get_parameter("STARTUP_TIMEOUT"),
--> 437 abort_event=_StartEvent(self.kernel_proc, self.trigger_termination_requested),
438 )
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/zmqsocket.py in recv_abortable(socket, timeout, abort_check_period, abort_event, **kwargs)
54 "Failed to read any message from socket %s after %.1f seconds and %i retries."
---> 55 % (socket.uri, time.perf_counter() - start, retry)
56 )
SocketOperationTimeout: Failed to read any message from socket tcp://127.0.0.1:39963 after 20.1 seconds and 200 retries.
During handling of the above exception, another exception occurred:
WolframKernelException Traceback (most recent call last)
<ipython-input-3-84c234a8332d> in <module>
----> 1 sess.start()
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/localsession.py in start(self, block, timeout)
155 self.terminate()
156 finally:
--> 157 raise e
158
159 def start_future(self):
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/localsession.py in start(self, block, timeout)
150 future = self.start_future()
151 if future and block:
--> 152 future.result(timeout=timeout)
153 except Exception as e:
154 try:
~/anaconda3/envs/detectron2/lib/python3.6/concurrent/futures/_base.py in result(self, timeout)
430 raise CancelledError()
431 elif self._state == FINISHED:
--> 432 return self.__get_result()
433 else:
434 raise TimeoutError()
~/anaconda3/envs/detectron2/lib/python3.6/concurrent/futures/_base.py in __get_result(self)
382 def __get_result(self):
383 if self._exception:
--> 384 raise self._exception
385 else:
386 return self._result
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py in run(self)
525 # Kernel start requested.
526 if payload is self.START:
--> 527 self._safe_kernel_start()
528 future.set_result(True)
529 future = None
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py in _safe_kernel_start(self)
364 self._kernel_terminate()
365 finally:
--> 366 raise e
367
368 _KERNEL_OK = b"OK"
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py in _safe_kernel_start(self)
358 """ Start a kernel. If something went wrong, clean-up resources that may have been created. """
359 try:
--> 360 self._kernel_start()
361 except Exception as e:
362 logger.warning("Failed to start.")
~/anaconda3/envs/detectron2/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py in _kernel_start(self)
454 logger.warning("Socket exception: %s", se)
455 raise WolframKernelException(
--> 456 "Failed to communicate with kernel: %s." % self.kernel
457 )
458
WolframKernelException: Failed to communicate with kernel: [path]
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 15 (7 by maintainers)
Here are some investigations to try narrow the source of bugs. The problem you’re facing is that the kernel process ends abruptly. @MaxKinny that’s why
self.subprocess.poll()has a value. Whereas it should beNoneas long as the process is running (see doc).Could you setup Python logging to see if there is anything useful printed using:
It’ll print to stdout. You should see the command used to start the WolframLanguage kernel. On my machine I get something like this:
Note that this is the code for
wolframclient 1.1.6. I’ll use it later, and you’d need to use the one printed on your machine, if running an older version of the library.Using this command, you can try to mock the python side with Wolfram Language and see if the problem remains.
In a fresh kernel, open two ZMQ sockets with appropriate types:
Now edit the starting command with the above ports. In my case the command becomes:
And run it in a terminal. Hopefully you’ll see an error in your terminal that will help debugging your issue.
While the above runs, go back to the kernel and run the following. First read the “OK” string returned when the process has started:
If you get this it means that the kernel initialization was successful. I doubt you’ll receive the message. But if you do, you can also try to evaluate something using: