Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Crash on missing rtree in environment without stderr #10666

Closed
neumannje opened this issue May 3, 2022 · 1 comment
Closed

[BUG] Crash on missing rtree in environment without stderr #10666

neumannje opened this issue May 3, 2022 · 1 comment
Assignees
Milestone

Comments

@neumannje
Copy link

Using sumolib.net.getNeighboringEdges in python, when

  • rtree is not installed
  • stderr is not available (None)

sumolib crashes: AttributeError: 'NoneType' object has no attribute 'write'

This is caused by https://github.com/eclipse/sumo/blob/main/tools/sumolib/net/__init__.py

288 except ImportError:
289   if allowFallback:
290     if not self.hasWarnedAboutMissingRTree:
291       sys.stderr.write("Warning: Module 'rtree' not available. Using brute-force fallback\n")
292       self.hasWarnedAboutMissingRTree = True

This environment is not rare or unlikely to encounter. The problem was encountered when using sumolib inside a QGIS Plugin.
When the QGIS Python Console is not open, sys.stderr is not available (sys.stderr == None).

Possible fix:

  • Check if sys.stderr is available, if not ignore printing the warning.
288 except ImportError:
289   if allowFallback:
290     if not self.hasWarnedAboutMissingRTree:
291       sys.stderr.write("Warning: Module 'rtree' not available. Using brute-force fallback\n") if sys.stderr else ...
292       self.hasWarnedAboutMissingRTree = True
293     else:
294       sys.stderr.write("Error: Module 'rtree' not available.\n") if sys.stderr else ...
295       sys.exit(1)
  • Add an option to suppress the warning
276 def getNeighboringEdges(self, x, y, r=0.1, includeJunctions=True,
277          allowFallback=True, supressWarning=False):
[...]
288   except ImportError:
289     if allowFallback:
290       if not self.hasWarnedAboutMissingRTree:
291         sys.stderr.write("Warning: Module 'rtree' not available. Using brute-force fallback\n") if not supressWarning else ...
292         self.hasWarnedAboutMissingRTree = True
293     else:
294       sys.stderr.write("Error: Module 'rtree' not available.\n") if not supressWarning else ...
295       sys.exit(1)

SUMO-version:

>>> sumolib.version.gitDescribe()
'v1_12_0+0000-800cb422fa4'

operating system:
N/A

@behrisch behrisch added this to the 1.14.0 milestone May 3, 2022
@behrisch behrisch self-assigned this May 3, 2022
@behrisch
Copy link
Contributor

behrisch commented May 5, 2022

fixed in 501bae7 It should be possible to disable warnings. Please add a comment if it does not help in your case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants