Exceptions raised in stdout instead of stderr
NicoRobertIn opened this issue · 1 comments
Issue Description:
Self explanatory... When an error is displayed, it is displayed in stdout where we should expect it displayed in stderr... Did I do something wrong?
Steps to Reproduce:
In the python script
from queue import Queue, Empty
from sys import builtin_module_names
from subprocess import Popen, PIPE, DEVNULL
from threading import Thread
from time import sleep
from atexit import register
from py4j.java_gateway import JavaGateway
def enqueue_output(out, queue):
for line in iter(out.readline, b''):
queue.put(line)
out.close()
ON_POSIX = 'posix' in builtin_module_names
error_queue = Queue()
def get_error_line():
try:
return error_queue.get_nowait()
except Empty:
return ""
def get_error_output():
total_output = []
current_line = "a"
while len(current_line) > 0:
current_line = get_error_line()
if isinstance(current_line, bytes):
current_line = current_line.decode('utf-8')
total_output.append(current_line)
return "\n".join(total_output).strip()
# Start java gateway
java_process = Popen(
['java', '-jar', '-Dfile.encoding=UTF-8', 'corese-library-python-4.4.1.jar'],
stdout=PIPE,
stderr=DEVNULL,
close_fds=ON_POSIX
)
reader_thread = Thread(target=enqueue_output, args=(java_process.stdout, error_queue))
reader_thread.daemon = True # thread dies with the program
reader_thread.start()
# Waiting for the java server to start up
sleep(1)
gateway = JavaGateway()
register(gateway.shutdown)
# Import of class
OWLProfile = gateway.jvm.fr.inria.corese.core.logic.OWLProfile
Graph = gateway.jvm.fr.inria.corese.core.Graph
Load = gateway.jvm.fr.inria.corese.core.load.Load
def load(path):
"""Load a graph from a local file or a URL
:param path: local path or a URL or a list of these
:returns: the graph load
"""
graph = Graph()
ld = Load.create(graph)
try:
get_error_output()
graph = Graph()
ld = Load.create(graph)
ld.parse(path)
syntax_errors = get_error_output()
print("syntax errors", syntax_errors)
return graph
except Exception as e:
# syntax_errors = parse_syntax_errors()
print("error", str(e).strip())
load("inconsistant.ttl")
In inconsistant.ttl:
@prefix owl: <http://www.w3.org/2002/07/owl#> .
ex:A a oxl:Class .
Expected Behavior:
The error should not be displayed since get_error_output does not capture stdout but stderr
Actual Behavior:
The print is syntax errors 11:06:20.857 [Thread-1] ERROR fr.inria.corese.sparql.triple.parser.ASTQuery - Undefined prefix: oxl:Class
Hello Nicolas,
Thank you for the report. I have fixed the problem by adding a configuration to the sparl
sub-project. This fix will be included in the upcoming release of Corese (version 4.4.2). You can test it now in the development branch.