Skip to content

Instantly share code, notes, and snippets.

@rendarz
Created December 21, 2020 20:10
Show Gist options
  • Save rendarz/fbadac091b0af526aaaacb6a603ee043 to your computer and use it in GitHub Desktop.
Save rendarz/fbadac091b0af526aaaacb6a603ee043 to your computer and use it in GitHub Desktop.
with self.lock:
current_list = namespace[name]
new_list = []
for element in current_list:
element.do_the_stuff()
if element.isAlive():
new_list.append(element)
with self.lock:
namespace[name] = new_list
# _____________________________________
with self.lock:
entry = get_first_entry_from_prio_queue()
entry.do_the_thing()
if entry.isAlive():
with self.lock():
insert_again_into_prio_queue(entry)
@amcgregor
Copy link

with self.lock:
  current_list = namespace[name]

new_list = [i for i in current_list if i.do_the_stuff().isAlive()]

with self.lock:
  namespace[name] = new_list

@rendarz
Copy link
Author

rendarz commented Dec 22, 2020

I have solved like this:

new_list = []
with self.lock:
  current_list = ns[name]
  for item in current_list:
    do_checkings()
    if item.isAlive():
      new_list.append(item)
  ns[name] = new_list

for item in new_list:
  item.do_lenghty_job()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment