Python Forum
how to do a two-way wait - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: how to do a two-way wait (/thread-36553.html)



how to do a two-way wait - Skaperen - Mar-03-2022

i did this once before. i'm still looking for that old code among 10000+ files. but i'm worried that code has some "clever" solution based on specific things it would wait for, probably done using lots of C-like syscalls. what i would like to know is a Pythonic way to wait for 2 or more things, to wake up when any one of them happens. i will not give specific examples to avoid replies based on those specific examples. i'm looking for general solutions to handle any case in Python.


RE: how to do a two-way wait - bowlofred - Mar-03-2022

My guess is you're wanting to do something like the equivalent of a select() for when some file descriptors have data, or you're using some sort of multithreaded/multiprocessing/async framework. I don't think there's any generic "wait for something".


RE: how to do a two-way wait - Skaperen - Mar-04-2022

your guess is on target.

i was thinking along the lines of some code that can wait for one of a list of 2 or more threads to quit. this function is passed a list of functions, each waits on the various things to wait on. the function launches a thread for each and waits for any one to quit. then it returns the index of which it was. the other threads probably should be killed.