GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||
GeezerVison is showing github.com — GH-93503: Add thread-specific APIs to set profiling and tracing functions in the C-API by pablogsal · Pull Request #93504 · python/cpython Conversation
|
|
I think this is too error prone, for a couple of reasons.
To be fair, this isn't just an issue with these functions, but any function that takes a #93503 is about adding an API to set tracing/profiling on all threads. Also, I don't like offering operations in the C-API that aren't available in Python. We shouldn't be forcing people to write C. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I am fine with that. Do you want me to update this PR or create another one?
That ship already sailed. Do mean that you would like to also expose such an API in the Python layer? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The threading module has setprofile() and settrace() functions. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
But those only work for newly created threads as I noted in the issue. They are used only when new threads are bootstrapped. What we are trying to do is to add APIs that affect all current threads. We also cannot change those for backwards compatibility, but we could place the new APIs in the thread module for Python access. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@markshannon you ok with this plan?
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes. Sounds good to me. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Would it make sense to add a parameter to these threading functions or to sys functions to apply the new tracing/profiling functions to existing threads? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I am ambivalent, but the new parameter sounds good if you prefer it that way. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ok, I have made a first version of the idea proposed by @markshannon. Please @vstinner @markshannon review again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I suggest all_threads=True rather than running_threads=True: in your implementation, threading.settrace() changes old and new threads, all threads, not only old ("running") threads.
With the PR, we have:
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@vstinner I'm going to change this PR to follow @markshannon request and make it a separate function in Python instead of a parameter. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sure, as you want. What would be the API in that case? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I have updated the APIs to use separate functions. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| } | ||
|
|
||
| void |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's not great that the function cannot report errors. While not returning -1 on error and pass the exception to the caller, rather than handling it with _PyErr_WriteUnraisableMsg()?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am mimicking what we do already in PyEval_SetProfile and to avoid surprises I think we should keep these two as synchronized as possible.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We cannot fix the API of old functions, but we can avoid past mistakes in newly added functions.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If you want to ignore exceptions on purpose, please mention it in the function documentation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If you want to ignore exceptions on purpose, please mention it in the function documentation.
Yeah, I want to do that because I don't want to stop setting the profile function on other threads if an exception in one fails. Unless you strongly disagree, I will document this.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I don't know if HEAD_LOCK/HEAD_UNLOCK is needed, I'm not sure if the GIL protects us here. The PyThreadState_Next() API is not well documented for thread safety :-(
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I plan to land this this week or the next one to avoid merge conflicts. @markshannon can you give it a last pass? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
One minor issue with the docs, otherwise LGTM.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Nice enhancement, thanks. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
You should document the newly added C API functions to: https://docs.python.org/dev/whatsnew/3.12.html#c-api-changes You should also document the new threading functions in the same document, in a threading section, near: https://docs.python.org/dev/whatsnew/3.12.html#improved-modules |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Add public APIs to set trace and profile function in other threads.
There was an error while loading. Please reload this page.