Skip to content

Instantly share code, notes, and snippets.

@Irfy
Irfy / so9269338.py
Last active February 19, 2019 10:51
Demonstrates a way to run blocking functions which require Ctrl-C handling capability on the main thread via queues from other threads in Python
from Queue import Queue, Empty
from functools import wraps
from threading import Thread, Semaphore
ctrlc_queue = Queue()
exit_sem = Semaphore(0) # Read: there are 0 ctrlc threads on start-up
def needs_ctrlc(fun):
@wraps(fun)
def wrapped(*args, **kwargs):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
using System.Collections.Concurrent;
using Microsoft.VisualStudio.TestTools.UnitTesting;