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

AttributeError: 'MemoryTempfile' object has no attribute 'tempdir' #12

Closed
goldyfruit opened this issue May 26, 2023 · 8 comments
Closed
Labels
bug Something isn't working

Comments

@goldyfruit
Copy link
Member

When starting the service on Mac OS (Python 3.11) without any mycroft.conf.

'MemoryTempfile' object has no attribute 'tempdir'
Traceback (most recent call last):
  File "/Users/goldyfruit/Virtualenvs/ovos/lib/python3.11/site-packages/combo_lock/combo_lock.py", line 117, in __init__
    path = join(get_ram_directory("combo_locks"), filename)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/goldyfruit/Virtualenvs/ovos/lib/python3.11/site-packages/combo_lock/util.py", line 7, in get_ram_directory
    path = os.path.join(tempfile.gettempdir(), folder)
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/goldyfruit/Virtualenvs/ovos/lib/python3.11/site-packages/memory_tempfile/memory_tempfile.py", line 80, in gettempdir
    return self.tempdir
           ^^^^^^^^^^^^
AttributeError: 'MemoryTempfile' object has no attribute 'tempdir'
@goldyfruit
Copy link
Member Author

Doesn't seem to be related to this service only. I got the same when starting ovos-dinkum-listener.

(ovos) goldyfruit@Gaetans-Air ~ % ~/Virtualenvs/ovos/bin/ovos-dinkum-listener 
'MemoryTempfile' object has no attribute 'tempdir'
Traceback (most recent call last):
  File "/Users/goldyfruit/Virtualenvs/ovos/lib/python3.11/site-packages/combo_lock/combo_lock.py", line 117, in __init__
    path = join(get_ram_directory("combo_locks"), filename)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/goldyfruit/Virtualenvs/ovos/lib/python3.11/site-packages/combo_lock/util.py", line 7, in get_ram_directory
    path = os.path.join(tempfile.gettempdir(), folder)
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/goldyfruit/Virtualenvs/ovos/lib/python3.11/site-packages/memory_tempfile/memory_tempfile.py", line 80, in gettempdir
    return self.tempdir
           ^^^^^^^^^^^^
AttributeError: 'MemoryTempfile' object has no attribute 'tempdir'
2023-05-26 16:04:38.621 - OVOS - ovos_utils.configuration:get_xdg_config_save_path:141 - WARNING - configuration moved to the `ovos_config` package. This submodule will be removed in ovos_utils 0.1.0
2023-05-26 16:04:38.683 - OVOS - ovos_utils.configuration:get_xdg_base:76 - WARNING - configuration moved to the `ovos_config` package. This submodule will be removed in ovos_utils 0.1.0
'MemoryTempfile' object has no attribute 'tempdir'
Traceback (most recent call last):
  File "/Users/goldyfruit/Virtualenvs/ovos/lib/python3.11/site-packages/combo_lock/combo_lock.py", line 117, in __init__
    path = join(get_ram_directory("combo_locks"), filename)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/goldyfruit/Virtualenvs/ovos/lib/python3.11/site-packages/combo_lock/util.py", line 7, in get_ram_directory
    path = os.path.join(tempfile.gettempdir(), folder)
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/goldyfruit/Virtualenvs/ovos/lib/python3.11/site-packages/memory_tempfile/memory_tempfile.py", line 80, in gettempdir
    return self.tempdir
           ^^^^^^^^^^^^
AttributeError: 'MemoryTempfile' object has no attribute 'tempdir'

@goldyfruit
Copy link
Member Author

Seems to be related to the fact that Mac OS doesn't have /dev/shm and memory_tempfile seems to create files in there.

@goldyfruit
Copy link
Member Author

According to their example, there is a "fallback" if the file can't be created into memory.

# We now do not want to use /dev/shm or /run/shm and no ramfs paths
# If /run/user/{uid} is available, we prefer it to /tmp
# And we want to try /var/run as a last resort
# If all fails, fallback to platform's tmp dir

from memory_tempfile import MemoryTempfile
import memory_tempfile

# By the way, all paths with string {uid} will have it replaced with the user id
tempfile = MemoryTempfile(preferred_paths=['/run/user/{uid}'], remove_paths=['/dev/shm', '/run/shm'],
                          additional_paths=['/var/run'], filesystem_types=['tmpfs'], fallback=True)

if tempfile.found_mem_tempdir():
    print('We could use any of the following paths: {}'.format(tempfile.get_usable_mem_tempdir_paths()))
    print('And we are using now: {}'.format(tempfile.gettempdir()))

with tempfile.NamedTemporaryFile() as ntf:
    # use it as usual...
    pass

@JarbasAl
Copy link
Member

fallback flag is passed https://github.com/forslund/combo-lock/blob/master/combo_lock/util.py#L6 ...

xfering issue to combo-lock repo

@JarbasAl
Copy link
Member

fixed in forslund/combo-lock#20 :)

@JarbasAl JarbasAl added the bug Something isn't working label May 27, 2023
@goldyfruit
Copy link
Member Author

All good!

(ovos) goldyfruit@Gaetans-Air ~ % ~/Virtualenvs/ovos/bin/ovos-messagebus
2023-05-27 11:32:27.812 - bus - ovos_messagebus.__main__:main:48 - INFO - Starting message bus service...
2023-05-27 11:32:27.814 - bus - ovos_messagebus.load_config:load_message_bus_config:33 - INFO - Loading message bus configs
2023-05-27 11:32:27.824 - bus - ovos_messagebus.__main__:on_ready:32 - INFO - Message bus service started!

@forslund
Copy link

Thanks for testing and verifying!

@goldyfruit
Copy link
Member Author

Thanks for testing and verifying!

Thanks for fixing!!!

@github-actions github-actions bot mentioned this issue Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants