threaded non-blocking close - #145
Conversation
|
Here is some output that shows that it still closes correctly: #!/usr/bin/python3
import evdev
import time
def a():
stuff = [evdev.InputDevice(path) for path in evdev.list_devices()]
time.sleep(10)
print('done')
return stuff
a()
print('sleep')
time.sleep(10)
print('end') |
|
Thanks for debugging this and providing a fix! |
|
I really hope it won't cause any unwanted side effects (race conditions) at some point in other applications. But it does make things easier, I had to put my stuff into a separate process to make sure things run smoothly. But thinking about it, it seems unlikely. Opening the device creates a new fd so it should be independent of the previous one, even if that one has exclusive access (since grabbing is process-wide, isn't it?) |
|
This patch ended up being the root cause for some weird hanging I was seeing when closing dragonfly; if I revert this back to a simple call to It might be something with trying to create a thread while python is shutting down? But also I'm not seeing the blocking effects with unthreaded
|
|
Do you know if asyncio supports closing files in a non-blocking way? Is a non-blocking close even theoretically possible with an event loop on a single process? |
|
Hmm yeah the code in #144 takes about a half second between printing and exiting for me, but that's definitely preferable to the indefinite hanging I was getting earlier. If I iterate over the devices in a loop and explicitly call As far as alternatives... I think the main issue comes from trying to do anything fancy inside of But in either case, (and from looking at what the CPython code does in some of its async stream handling), I think the right call is to leave it as a simple |
|
How about adding a parameter to the I'll quickly draft something and share it here. I'm not sure if that is good design though since it would still be a workaround, idk. |
|
I'm totally fine with reverting it completely if you are also not sure if adding a parameter for this is good design. In my project it is in a separate process anyway, so it won't be negatively affected by removing the threading |
|
I agree that adding a parameter doesn't feel like a good design, I'd prefer just reverting it. It's probably still a good idea to have text somewhere documenting this behavior though, just so other users are aware going into it. |
see #144
I don't know if the rest of the code relies on a blocking os.close, but it solves my issue. It doesn't seem to cause any unwanted side effects in my use case (https://github.com/sezanzeb/key-mapper), everything works fine.