Karthik | Langtrace AI
Karthik | Langtrace AI•16mo ago

Decorators with def main() not working in python

I am running into the following issue when I use a decorator with def main()
error:
ExecutionErr: error during execution of the script:
Error parsing code: Got unexpected EOF at byte offset 617
error:
ExecutionErr: error during execution of the script:
Error parsing code: Got unexpected EOF at byte offset 617
Wondering if this is windmill runtime specific config issue? It works well if I use the decorator on any other method and call it inside main. See below the code:
def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper

@my_decorator
def main():
print("The main function is running.")
def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper

@my_decorator
def main():
print("The main function is running.")
8 Replies
rubenf
rubenf•16mo ago
We will take a look
Karthik | Langtrace AI
Karthik | Langtrace AIOP•16mo ago
Thank you
Hugo
Hugo•16mo ago
This is now fixed
Reckless
Reckless•3w ago
@Hugo The solution works fine when the decorator is declared in the same file, but if you import the decorator from a separate script, I get this error:
@my_decorator
^^^^^^^^^^^^
TypeError: 'module' object is not callable
@my_decorator
^^^^^^^^^^^^
TypeError: 'module' object is not callable
Here is the code:
# f/sentry/decorators.py
def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper


# f/sentry/example.py
from f.sentry.decorators import my_decorator

@my_decorator
def main():
print("Running main...")
# f/sentry/decorators.py
def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper


# f/sentry/example.py
from f.sentry.decorators import my_decorator

@my_decorator
def main():
print("Running main...")
rubenf
rubenf•3w ago
try calling a function without it being a decorator. I think it's the import that fails (the function being in the relative import)
Reckless
Reckless•3w ago
Yes, it also fails, is it bc it's in a directory?
rubenf
rubenf•3w ago
did you deploy the relative script? you need to before it's importable
Reckless
Reckless•3w ago
I didn't 😅, it's working now, thanks

Did you find this page helpful?