ModuleNotFoundError: import of time halted; None in sys.modules
Hi there. I was trying out some of the example codes from readthedocs, and when trying out the following sound example:
import ev3_dc as ev3
from time import sleep
hugo = ev3.Sound(protocol=ev3.USB, host='00:16:53:54:43:18', volume=20)
hugo.verbosity = 1
hugo.play_sound(
'./ui/DownloadSucces.rsf',
repeat=False
)
sleep(5)
hugo.stop_sound()
I get the following error:
20:40:07.754633 Sent 0x|1D:00|2C:00|00|00:00|94:02:14:84:2E:2F:75:69:2F:44:6F:77:6E:6C:6F:61:64:53:75:63:63:65:73:00|
20:40:07.763413 Recv 0x|03:00|2C:00|02|
20:40:12.780495 Sent 0x|07:00|2D:00|00|00:00|94:00|
20:40:12.788453 Recv 0x|03:00|2D:00|02|
Exception ignored in: <function Sound.__del__ at 0x00000198163A2C10>
Traceback (most recent call last):
File "C:\...\ev3_dc\sound.py", line 303, in __del__
File "C:\...\ev3_dc\file.py", line 476, in del_dir
File "C:\...\ev3_dc\ev3.py", line 1222, in send_direct_cmd
File "C:\...\ev3_dc\ev3.py", line 545, in send_direct_cmd
ModuleNotFoundError: import of time halted; None in sys.modules
I'm currently running python 3.9.12 on Windows 10. The version of ev3_dc is 0.9.10.1.
I've seen this error online before, but couldn't find a suitable fix. Here is a relevant issue, https://bugs.python.org/issue31642
However, if I run the code through the VS Code debugger, it runs perfectly fine except for some extra commands output:
21:03:08.393088 Sent 0x|1D:00|2C:00|00|00:00|94:02:14:84:2E:2F:75:69:2F:44:6F:77:6E:6C:6F:61:64:53:75:63:63:65:73:00|
21:03:08.401083 Recv 0x|03:00|2C:00|02|
21:03:13.409712 Sent 0x|07:00|2D:00|00|00:00|94:00|
21:03:13.414404 Recv 0x|03:00|2D:00|02|
21:03:13.418414 Sent 0x|12:00|2E:00|00|01:00|C0:0D:84:2E:2E:2F:70:72:6A:73:2F:00:60|
21:03:13.424046 Recv 0x|04:00|2E:00|02|02|
21:03:13.426851 Sent 0x|15:00|2F:00|00|40:00|C0:0F:84:2E:2E:2F:70:72:6A:73:2F:00:01:81:40:60|
21:03:13.431465 Recv 0x|43:00|2F:00|02|42:72:6B:50:72:6F:67:5F:53:41:56:45:00:00:7E:00:70:17:00:00:34:12:00:00:1E:00:45:56:33:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:4C:69:6E:75:78:20|
21:03:13.435360 Sent 0x|15:00|30:00|00|40:00|C0:0F:84:2E:2E:2F:70:72:6A:73:2F:00:02:81:40:60|
21:03:13.443420 Recv 0x|43:00|30:00|02|73:6F:75:6E:64:00:67:5F:53:41:56:45:00:00:7E:00:70:17:00:00:34:12:00:00:1E:00:45:56:33:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:4C:69:6E:75:78:20|
21:03:13.443420 Sent 0x|12:00|31:00|00|00:00|C0:18:84:2E:2E:2F:70:72:6A:73:2F:00:02|
21:03:13.455643 Recv 0x|03:00|31:00|02|
Running the code in python's IDLE works as normal though. I tried the code in Sublime Text and got the same error as VS Code. Not too sure what to do now
Thanks in advance.
Hello,
your error is thrown, when python shuts down. Part of method del of your Sound object is to delete the temporary directory on your EV3 brick. This fails when it tries to print.
Can you please explicitly delete your Sound object by adding a last line:
del hugo
Another option, which may help, is to use the with statement:
with ev3.Sound(protocol=ev3.USB, host='00:16:53:54:43:18', volume=20) as hugo:
I hope, one of the options helps.
Kind regards, Christoph
Both solutions worked, but the first one outputted a lot more commands than the second, but thanks for the help.
One question though, if the del keyword is required at the end, does that mean python isn't deleting the variable/object itself? Is there a reason behind this?