-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Thread Safe Py_AddPendingCall #48543
Comments
At CCP We have started using the Py_AddPendingCall() mechanism to |
Your patch sounds like a useful addition. However I can comment on the Documentation updates and a unit test (Modules/_testcapimodule.c), that |
Good point. I'll make a test using ctypes and _testcapimodule.c to try |
Okay, i add a new patch that includes tests. |
Py_AddPendingCall is used inside signal handlers. |
Right. |
Here is a revised version. |
Small refinement: Deadlock avoidance is only needed on the main thread |
Two comments about the patch:
|
I had forgotten that locks aren't initialized until PyEval_InitThreads |
I turns out that for SIGINT, windows creates a new thread. So, the |
Ping. |
A note to people concerned by performance: the additional lock is used |
Good points. |
Well, I could not find these functions documented anywhere :-( At the very least, a short sentence in whatsnew/2.7.rst would be |
Ok, here is a revised, patch. |
Would it be possible to rework your code so as not to define two Also, it would be nice to have a test for this specific feature (e.g. |
Ah, I forgot the test code in my patch. I submit a separate patch to |
A few comments about the test:
I will look at the ceval part of the patch later :) |
Thanks. Also, atomicity in the callback is not required, as the callback is As for your other suggestions, they're noted, I'll try having more |
Ok, I have addressed the issues raised about testcapi. A new file has |
Ok, the test patch is fine! Now looking at the main patch, some comments:
|
Sorry, forget what I said about the GIL, it looks fine. Perhaps some |
I have also added a flag to make sure that we don't execute pending |
Checked in as revision: 68460 |
Looks like you forgot the unit tests! |
I indeed forgot the unittests and docs. |
Added MISC/News entry in revision: 68545 |
Kristján, The r68461 checkin seems to be causing a number of the buildbots to fail, test_capi
test test_capi failed -- Traceback (most recent call last):
File "/home/pybot/buildarea/trunk.klose-debian-ppc/build/Lib/test/test_capi.py", line 57, in
test_pendingcalls_threaded
self.pendingcalls_wait(l, n)
File "/home/pybot/buildarea/trunk.klose-debian-ppc/build/Lib/test/test_capi.py", line 42, in
pendingcalls_wait
"timeout waiting for %i callbacks, got %i"%(n, len(l)))
AssertionError: timeout waiting for 32 callbacks, got 23 Please could you look into this? Also, I don't understand the code: for i in xrange(1000):
a = i*i in pendingcalls_wait(), in test_capi.py. Whatever you're |
How about using a timer instead of the 'count += 1' loop: after starting Then your waiting loop could be something like: while not self.my_event.is_set():
for i in range(1000):
a = i*i
self.assertEqual(len(l), n) There's probably a better way, but that's the best I can come up with this |
checked in r68722, let's hope this fixes things. |
That seems to have done the trick. Thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: