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

Close Logfile Command is missing #556

Open
patorf opened this issue Apr 5, 2024 · 1 comment
Open

Close Logfile Command is missing #556

patorf opened this issue Apr 5, 2024 · 1 comment

Comments

@patorf
Copy link

patorf commented Apr 5, 2024

Hallo,
we are using the esmini.dll in python like this:

esminiLib = cdll.LoadLibrary(esmini.lib_path))
log_file_path_pointer = c_char_p(log_file_path.encode(encoding="utf-8")) 
esminiLib.SE_SetLogFilePath(log_file_path_pointer)
esminiLib.SE_Init(....)
...
esminiLib.SE_Close()

After the simulation we want to delete the folder where the logfile was saved. Unfortunately we get the following error:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: path\to\logfile.log'

Could you add a funtion to close the logfile or that this happens within the SE_Close() function?

eknabevcc added a commit that referenced this issue Apr 5, 2024
@eknabevcc
Copy link
Collaborator

Very good find and proposal.

We choose to add close function. Default will still be to keep open for potential multiple runs. Now user/programmer can choose whether to append (keep open) or start over (close and delete).

Now, with commit db03994 and release v2.37.6, this code should work:

import ctypes
import sys
import os

if sys.platform == "linux" or sys.platform == "linux2":
    se = ctypes.CDLL("../bin/libesminiLib.so")
elif sys.platform == "darwin":
    se = ctypes.CDLL("../bin/libesminiLib.dylib")
elif sys.platform == "win32":
    se = ctypes.CDLL("../bin/esminiLib.dll")
else:
    print("Unsupported platform: {}".format(sys.platform))
    quit()

if (len(sys.argv) < 2):
    print('Usage: {} <xosc file>'.format(sys.argv[0]))
    exit(-1)

log_file_path = "emil.log"
se.SE_SetLogFilePath(log_file_path.encode())

se.SE_Init(sys.argv[1].encode('ascii'), 0, 1, 0, 0)
while not se.SE_GetQuitFlag():
    se.SE_Step()
se.SE_Close()

se.SE_CloseLogFile()

os.remove(log_file_path)

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

No branches or pull requests

2 participants