-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
avoid cancel_handle close race with weakref.finalize #2374
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2374 +/- ##
==========================================
- Coverage 92.45% 92.42% -0.04%
==========================================
Files 118 118
Lines 16342 16348 +6
Branches 3155 3156 +1
==========================================
Hits 15109 15109
- Misses 1104 1110 +6
Partials 129 129
|
at the beginning I wanna make pynorm https://github.com/USNavalResearchLaboratory/norm work with import pynorm
instance:pynorm.Instance = pynorm.Instance()
async def watch_norm_events():
'''
NormGetNextEvent docs : non-blocking operation may be achieved by using the NormGetDescriptor() function
to obtain a descriptor(int for Unix or HANDLE for WIN32) suitable for
asynchronous input/output (I/O) notification
using such system calls the Unix select() or Win32 WaitForMultipleObjects() calls.
The descriptor is signaled when a notification event is pending and a call to
NormGetNextEvent() will not block
'''
global instance
#instance.setDebugLevel(level=12)
handle = instance.getDescriptor() #handler opened by norm lib
while True:
await WaitForSingleObject(handle) # wait for event
event: pynorm.event.Event = instance.getNextEvent( )
print(event) |
84b54b7
to
8746c5f
Compare
2a38d2f
to
8cc62c9
Compare
This PR has 100% diff branch coverage on my machine. |
try: | ||
await trio.to_thread.run_sync( | ||
WaitForMultipleObjects_sync, | ||
handle, | ||
cancel_handle, | ||
cancellable=True, | ||
limiter=trio.CapacityLimiter(math.inf), | ||
limiter=trio.CapacityLimiter(1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for this change? The two versions should act the same, given that we're creating a new CapacityLimiter
on every call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing super important, but it avoids an import and an attribute lookup. Do you remember why the default thread limiter is not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just answering my own question here: #4 (comment)
with regression test
Fixes #1271. This is essentially the reference counting scheme from that issue, but python is doing the refcounting. I've also made sure the "nonblocking" case is a full checkpoint, win32 errors don't pass silently, and the logic is protected from
KeyboardInterrupt
.I wrote this in response to #1834 (comment) where @honglei seemed more interested in the bugfix than the features of #1834. (Hopefully you can test this branch in your application?)
Ideally, if someone reviews this they would also have a look at #1834 so I can either close or merge that one.