iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.59k stars 3.88k forks source link

tools/*.py: fix invalid escape sequences in regexps #4789

Closed hhoffstaette closed 1 year ago

hhoffstaette commented 1 year ago

With python >=3.8 many tools emit warnings on startup:

/usr/sbin/dcstat:91: SyntaxWarning: invalid escape sequence '\d'
  b.attach_kprobe(event_re="^lookup_fast$|^lookup_fast.constprop.*.\d$", fn_name="count_fast")

Fix this by ~properly escaping backslashes~ using raw strings for regular expressions.

hhoffstaette commented 1 year ago

In case I missed any candidates please let me know and I'll add them.

yonghong-song commented 1 year ago

I somehow cannot reproduce the warning with my local env (python 3.9). But I verified that the change works for 3.6 and 3.9 in my local env. Also the changed format is what python3 recommended https://docs.python.org/3/library/re.html.

hhoffstaette commented 1 year ago

I somehow cannot reproduce the warning with my local env (python 3.9). But I verified that the change works for 3.6 and 3.9 in my local env. Also the changed format is what python3 recommended https://docs.python.org/3/library/re.html.

Hm.. I'm on 3.12 already and when I searched for the warning, various results indicated that this happens since 3.8. Might only be since 3.10, but whatever - as you said it's the right thing to do anyway. Thanks for merging. :)