Exception in exportDXF: AttributeError on time.clock #76610

Closed
opened 2020-05-10 10:36:39 +02:00 by Paul Morelle · 8 comments

System Information
Operating system: ArchLinux
Graphics card: GeForce GTX 1050
Python version: 3.8

Blender Version
Broken: 2.82a

Short description of error
When exporting to the DXF format, there is an exception because the module time has no attribute clock in Python 3.8

Exact steps for others to reproduce the error

  1. File > Export > AutoCAD DXF
  2. Export DXF
Traceback (most recent call last):
  File "/usr/share/blender/2.82/scripts/addons/io_export_dxf/operator.py", line 289, in execute
    exportDXF(context, filePath, config)
  File "/usr/share/blender/2.82/scripts/addons/io_export_dxf/export_dxf.py", line 38, in exportDXF
    time1 = time.clock()
AttributeError: module 'time' has no attribute 'clock'

location: <unknown location>:-1

The problem is that the clock attribute has been deprecated since Python 3.3, and has been removed in Python 3.8.

The function time.clock() has been removed, after having been deprecated since Python 3.3: use time.perf_counter() or time.process_time() instead, depending on your requirements, to have well-defined behavior. (Contributed by Matthias Bussonnier in bpo-36895.)

(https://docs.python.org/3/whatsnew/3.8.html#api-and-feature-removals)

Proposed patch:

diff --git a/io_export_dxf/export_dxf.py b/io_export_dxf/export_dxf.py
index 88a27b3b..5530c8c1 100644
--- a/io_export_dxf/export_dxf.py
+++ b/io_export_dxf/export_dxf.py
@@ -34,8 +34,12 @@ def exportDXF(context, filePath, settings):
     Main entry point into export facility.
     """
     print("----------\nExporting to {}".format(filePath))
-    import time
-    time1 = time.clock()
+    try:
+        from time import perf_counter as timestamp
+    except ImportError:
+        # Python < 3.3
+        from time import clock as timestamp
+    time1 = timestamp()
 
     if settings['verbose']:
         print("Generating Object list for export... (Root parents only)")
@@ -71,7 +75,7 @@ def exportDXF(context, filePath, settings):
 
             drawing.convert(filePath)
 
-        duration = time.clock() - time1
+        duration = timestamp() - time1
         print('%s objects exported in %.2f seconds. -----DONE-----' %\
             (exported, duration))
     except IOError:
**System Information** Operating system: ArchLinux Graphics card: GeForce GTX 1050 Python version: 3.8 **Blender Version** Broken: 2.82a **Short description of error** When exporting to the DXF format, there is an exception because the module `time` has no attribute `clock` in Python 3.8 **Exact steps for others to reproduce the error** 1. File > Export > AutoCAD DXF 2. Export DXF ``` Traceback (most recent call last): File "/usr/share/blender/2.82/scripts/addons/io_export_dxf/operator.py", line 289, in execute exportDXF(context, filePath, config) File "/usr/share/blender/2.82/scripts/addons/io_export_dxf/export_dxf.py", line 38, in exportDXF time1 = time.clock() AttributeError: module 'time' has no attribute 'clock' location: <unknown location>:-1 ``` The problem is that the `clock` attribute has been deprecated since Python 3.3, and has been removed in Python 3.8. > The function time.clock() has been removed, after having been deprecated since Python 3.3: use time.perf_counter() or time.process_time() instead, depending on your requirements, to have well-defined behavior. (Contributed by Matthias Bussonnier in bpo-36895.) (https://docs.python.org/3/whatsnew/3.8.html#api-and-feature-removals) Proposed patch: ``` diff --git a/io_export_dxf/export_dxf.py b/io_export_dxf/export_dxf.py index 88a27b3b..5530c8c1 100644 --- a/io_export_dxf/export_dxf.py +++ b/io_export_dxf/export_dxf.py @@ -34,8 +34,12 @@ def exportDXF(context, filePath, settings): Main entry point into export facility. """ print("----------\nExporting to {}".format(filePath)) - import time - time1 = time.clock() + try: + from time import perf_counter as timestamp + except ImportError: + # Python < 3.3 + from time import clock as timestamp + time1 = timestamp() if settings['verbose']: print("Generating Object list for export... (Root parents only)") @@ -71,7 +75,7 @@ def exportDXF(context, filePath, settings): drawing.convert(filePath) - duration = time.clock() - time1 + duration = timestamp() - time1 print('%s objects exported in %.2f seconds. -----DONE-----' %\ (exported, duration)) except IOError: ```
Author

Added subscriber: @madprog

Added subscriber: @madprog
Member

Added subscriber: @ankitm

Added subscriber: @ankitm
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Please submit a patch on https://developer.blender.org/differential/diff/create/
Also, it's helpful to read the guidelines listed on the top.

Isn't time.time()usable though.

Please submit a patch on https://developer.blender.org/differential/diff/create/ Also, it's helpful to read the guidelines listed on the top. Isn't `time.time()`usable though.

This issue was referenced by b4f07c45de

This issue was referenced by b4f07c45de2e012bf7342cc17974f4065fe73fdf

Added subscriber: @brecht

Added subscriber: @brecht

I committed the fix now, but no need for backwards compatibility for older Python versions.

I committed the fix now, but no need for backwards compatibility for older Python versions.

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Brecht Van Lommel self-assigned this 2020-05-10 14:14:35 +02:00
Sign in to join this conversation.
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-addons#76610
No description provided.