Blender crashes when calling ArgumentParser.parse_args() if sys.argv is anything other than ["path/to/blender.exe"] #109435

Closed
opened 2023-06-28 11:56:02 +02:00 by Tristan-Languebien · 3 comments

System Information
Operating system: Windows-10-10.0.19044-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 980 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.18

Blender Version
Broken: version: 3.5.1, branch: blender-v3.5-release, commit date: 2023-04-24 18:11, hash: e1ccd9d4a1d3
Worked: (newest version of Blender that worked as expected)

Short description of error
Blender crashes when calling ArgumentParser.parse_args() if sys.argv is anything other than ["path/to/blender.exe"]
I discovered this bug while trying to run a script using the exec() function. Any script that uses argparse makes blender crash.

Exact steps for others to reproduce the error
You can run this code

import argparse
import sys
import bpy

sys.argv = [bpy.app.binary_path]
sys.argv.append("--some_arg") # Comment this line and everything works fine

parser = argparse.ArgumentParser()
args = parser.parse_args()
**System Information** Operating system: Windows-10-10.0.19044-SP0 64 Bits Graphics card: NVIDIA GeForce GTX 980 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.18 **Blender Version** Broken: version: 3.5.1, branch: blender-v3.5-release, commit date: 2023-04-24 18:11, hash: `e1ccd9d4a1d3` Worked: (newest version of Blender that worked as expected) **Short description of error** Blender crashes when calling `ArgumentParser.parse_args()` if `sys.argv` is anything other than `["path/to/blender.exe"]` I discovered this bug while trying to run a script using the `exec()` function. Any script that uses argparse makes blender crash. **Exact steps for others to reproduce the error** You can run this code ```Py import argparse import sys import bpy sys.argv = [bpy.app.binary_path] sys.argv.append("--some_arg") # Comment this line and everything works fine parser = argparse.ArgumentParser() args = parser.parse_args() ```
Tristan-Languebien added the
Status
Needs Triage
Type
Report
Priority
Normal
labels 2023-06-28 11:56:03 +02:00
Iliya Katushenock added the
Interest
Python API
label 2023-06-28 11:58:57 +02:00
Member

Huh I can crash it from text editor but not from python console in blender. Interesting.

if ran in python console args would just be Namespace()

>>> import argparse
>>> import sys
>>> import bpy
>>> sys.argv = [bpy.app.binary_path]
>>> parser = argparse.ArgumentParser()
>>> args = parser.parse_args()
>>> 
>>> args
Namespace()

Huh I can crash it from text editor but not from python console in blender. Interesting. if ran in python console `args` would just be `Namespace()` ```python >>> import argparse >>> import sys >>> import bpy >>> sys.argv = [bpy.app.binary_path] >>> parser = argparse.ArgumentParser() >>> args = parser.parse_args() >>> >>> args Namespace() ```
YimingWu added
Module
Python API
Status
Confirmed
and removed
Status
Needs Triage
labels 2023-06-28 14:36:12 +02:00

I noticed some python events can shutdown blender. In console the error is caucht (but notice that executing it twice with arrow up causes sytax error. What?). So we probably have 2 bugs here.

>>> exit(1)
Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\scripts\modules\console_python.py", line 150, in execute
    is_multiline = console.push(line_exec)
  File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\python\lib\code.py", line 258, in push
    more = self.runsource(source, self.filename)
  File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\python\lib\code.py", line 74, in runsource
    self.runcode(code)
  File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\python\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<blender_console>", line 1, in <module>
  File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\python\lib\_sitebuiltins.py", line 26, in __call__
    raise SystemExit(code)
SystemExit: 1

>>> exit(1)
  File "<blender_console>", line 1
    exit(1)
           ^
SyntaxError: multiple statements found while compiling a single statement

Executing exit(123) in text editor in shutsdown blender with error code 123. That is actually pretty funny :)

The behaviour that you see is python library argparse "raising" an error by calling exit(2).
I will try to fix it, but it will take ma long-ish time.

I noticed some python events can shutdown blender. In console the error is caucht (but notice that executing it twice with arrow up causes sytax error. What?). So we probably have 2 bugs here. ```python >>> exit(1) Traceback (most recent call last): File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\scripts\modules\console_python.py", line 150, in execute is_multiline = console.push(line_exec) File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\python\lib\code.py", line 258, in push more = self.runsource(source, self.filename) File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\python\lib\code.py", line 74, in runsource self.runcode(code) File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\python\lib\code.py", line 90, in runcode exec(code, self.locals) File "<blender_console>", line 1, in <module> File "C:\Program Files\Blender Foundation\Blender 3.3\3.3\python\lib\_sitebuiltins.py", line 26, in __call__ raise SystemExit(code) SystemExit: 1 >>> exit(1) File "<blender_console>", line 1 exit(1) ^ SyntaxError: multiple statements found while compiling a single statement ``` Executing `exit(123)` in text editor in shutsdown blender with error code 123. That is actually pretty funny :) The behaviour that you see is python library `argparse` "raising" an error by calling exit(2). I will try to fix it, but it will take ma long-ish time.

Calls to sys.exit will exit Blender, this isn't a crash but as this report shows, it can seem like a crash.

The argparse module is part of Python, in general if Python's own modules call sys.exit() this is not something Blender prevents.

If you want to override this you can sub-class argparse.ArgumentParser and an alternative exit method (see its documentation).

So I wouldn't consider this a bug.


The issue you mentioned with the Python console showing a stack trace then a syntax error for further input is a bug since the input from the previous command isn't cleared. Fixed: 489408e8d3.

Calls to sys.exit will exit Blender, this isn't a crash but as this report shows, it can seem like a crash. The `argparse` module is part of Python, in general if Python's own modules call sys.exit() this is not something Blender prevents. If you want to override this you can sub-class `argparse.ArgumentParser` and an alternative exit method (see its documentation). So I wouldn't consider this a bug. ---- The issue you mentioned with the Python console showing a stack trace then a syntax error for further input is a bug since the input from the previous command isn't cleared. Fixed: 489408e8d37a35b19d08354f880d00f85422d591.
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2024-01-16 07:24:58 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#109435
No description provided.