@@ -887,7 +887,8 @@ def validate_executable():
887
887
>>> plotly.io.orca.config.save()
888
888
889
889
If you're still having trouble, feel free to ask for help on the forums at
890
- https://community.plot.ly/c/api/python"""
890
+ https://community.plot.ly/c/api/python
891
+ """
891
892
892
893
# Try to find an executable
893
894
# -------------------------
@@ -914,50 +915,96 @@ def validate_executable():
914
915
# ---------------------------------------------------
915
916
invalid_executable_msg = """
916
917
The orca executable is required in order to export figures as static images,
917
- but the executable that was found at '{executable}' does not seem to be a
918
- valid plotly orca executable.
918
+ but the executable that was found at '{executable}'
919
+ does not seem to be a valid plotly orca executable. Please refer to the end of
920
+ this message for details on what went wrong.
919
921
920
922
{instructions}""" .format (
921
923
executable = executable ,
922
924
instructions = install_location_instructions )
923
925
924
- try :
925
- help_result = subprocess .check_output ([executable , '--help' ])
926
- except subprocess .CalledProcessError :
927
- raise ValueError (invalid_executable_msg )
926
+ # ### Run with Popen so we get access to stdout and stderr
927
+ p = subprocess .Popen (
928
+ [executable , '--help' ],
929
+ stdout = subprocess .PIPE ,
930
+ stderr = subprocess .PIPE )
931
+
932
+ help_result , help_error = p .communicate ()
933
+
934
+ if p .returncode != 0 :
935
+ err_msg = invalid_executable_msg + """
936
+ Here is the error that was returned by the command
937
+ $ {executable} --help
938
+
939
+ [Return code: {returncode}]
940
+ {err_msg}
941
+ """ .format (executable = executable ,
942
+ err_msg = help_error .decode ('utf-8' ),
943
+ returncode = p .returncode )
944
+
945
+ # Check for Linux without X installed.
946
+ if (sys .platform .startswith ('linux' ) and
947
+ not os .environ .get ('DISPLAY' )):
948
+
949
+ err_msg += """\
950
+ Note: When used on Linux, orca requires an X11 display server, but none was
951
+ detected. Please install X11, or configure your system with Xvfb. See
952
+ the orca README (https://github.com/plotly/orca) for instructions on using
953
+ orca with Xvfb.
954
+ """
955
+ raise ValueError (err_msg )
928
956
929
957
if not help_result :
930
- raise ValueError (invalid_executable_msg )
958
+ raise ValueError (invalid_executable_msg + """
959
+ The error encountered is that no output was returned by the command
960
+ $ {executable} --help
961
+ """ .format (executable = executable ))
931
962
932
963
if ("Plotly's image-exporting utilities" not in
933
964
help_result .decode ('utf-8' )):
934
- raise ValueError (invalid_executable_msg )
965
+ raise ValueError (invalid_executable_msg + """
966
+ The error encountered is that unexpected output was returned by the command
967
+ $ {executable} --help
968
+
969
+ {help_result}
970
+ """ .format (executable = executable , help_result = help_result ))
935
971
936
972
# Get orca version
937
973
# ----------------
938
- try :
939
- orca_version = subprocess .check_output ([executable , '--version' ])
940
- except subprocess .CalledProcessError :
941
- raise ValueError ("""
942
- An error occurred while trying to get the version of the orca executable.
943
- Here is the command that plotly.py ran to request the version:
974
+ # ### Run with Popen so we get access to stdout and stderr
975
+ p = subprocess .Popen (
976
+ [executable , '--version' ],
977
+ stdout = subprocess .PIPE ,
978
+ stderr = subprocess .PIPE )
944
979
980
+ version_result , version_error = p .communicate ()
981
+
982
+ if p .returncode != 0 :
983
+ raise ValueError (invalid_executable_msg + """
984
+ An error occurred while trying to get the version of the orca executable.
985
+ Here is the command that plotly.py ran to request the version
945
986
$ {executable} --version
946
- """ .format (executable = executable ))
947
987
948
- if not orca_version :
949
- raise ValueError ("""
950
- No version was reported by the orca executable.
988
+ This command returned the following error:
989
+
990
+ [Return code: {returncode}]
991
+ {err_msg}
992
+ """ .format (executable = executable ,
993
+ err_msg = version_error .decode ('utf-8' ),
994
+ returncode = p .returncode ))
951
995
996
+ if not version_result :
997
+ raise ValueError (invalid_executable_msg + """
998
+ The error encountered is that no version was reported by the orca executable.
952
999
Here is the command that plotly.py ran to request the version:
953
1000
954
1001
$ {executable} --version
955
1002
""" .format (executable = executable ))
956
1003
else :
957
- orca_version = orca_version .decode ()
1004
+ version_result = version_result .decode ()
958
1005
959
1006
status ._props ['executable' ] = executable
960
- status ._props ['version' ] = orca_version .strip ()
1007
+ status ._props ['version' ] = version_result .strip ()
961
1008
status ._props ['state' ] = 'validated'
962
1009
963
1010
@@ -1012,18 +1059,28 @@ def shutdown_server():
1012
1059
# process. This prevents any zombie processes from being
1013
1060
# left over, and it saves us from needing to write
1014
1061
# OS-specific process management code here.
1062
+
1015
1063
parent = psutil .Process (orca_state ['proc' ].pid )
1016
1064
for child in parent .children (recursive = True ):
1017
- child .terminate ()
1018
-
1019
- # Kill parent process
1020
- orca_state ['proc' ].terminate ()
1021
-
1022
- # Retrieve standard out and standard error to avoid warnings
1023
- output , err = orca_state ['proc' ].communicate ()
1024
-
1025
- # Wait for the process to shutdown
1026
- child_status = orca_state ['proc' ].wait ()
1065
+ try :
1066
+ child .terminate ()
1067
+ except :
1068
+ # We tried, move on
1069
+ pass
1070
+
1071
+ try :
1072
+ # Kill parent process
1073
+ orca_state ['proc' ].terminate ()
1074
+
1075
+ # Retrieve standard out and standard error to avoid
1076
+ # warnings
1077
+ output , err = orca_state ['proc' ].communicate ()
1078
+
1079
+ # Wait for the process to shutdown
1080
+ child_status = orca_state ['proc' ].wait ()
1081
+ except :
1082
+ # We tried, move on
1083
+ pass
1027
1084
1028
1085
# Update our internal process management state
1029
1086
orca_state ['proc' ] = None
0 commit comments