Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python "@" cause SyntaxError: invalid syntax

pyrapl:
https://pypi.org/project/pyRAPL/

import os
import pyRAPL

pyRAPL.setup() 
csv_output = pyRAPL.outputs.CSVOutput('result.csv')

command = "stress -c 4 -t 10"

@pyRAPL.measure(output=csv_output)

os.system("stress -c 4 -t 10")

csv_output.save()

python rapl_log.py

output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


  File "/home/edison/Downloads/rapl_log.py", line 11
    os.system("stress -c 4 -t 10")
    ^^
SyntaxError: invalid syntax

How can I fix this problem? I think that may caused by the "@" in "@pyRAPL.measure(output=csv_output)", but I am new to python~.

I hope to use pyrapl to log the energy value for run "stress".

>Solution :

The @ symbol is used for decorators, which modify functions, so you need to wrap your code in a function. Perhaps this modified version of your code would work:

Example slightly modified from the docs:

import pyRAPL

pyRAPL.setup()

csv_output = pyRAPL.outputs.CSVOutput('result.csv')

@pyRAPL.measure(output=csv_output)
def foo():
    # Instructions to be evaluated.
    os.system("stress -c 4 -t 10")

for _ in range(100):
    foo()

csv_output.save()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading