Use CriticalSection to prevent deadlocks on dequeue

This `q_id` value appears to be a process-local value (the memory address of the `q` object), which makes me wonder how is the use of `CriticalSection` is any better than than a plain `queue.Queue` object (`queue.Queue` is thread-safe within a process)?