Skip to content

Hide debugger threads from being returned in the threading module #202

@jbelusic

Description

@jbelusic

This code should go to end but in VS Code does not. In others IDE this run to the end.
Is this BUG or?

Code is:

import logging
import random
import threading
import time

logging.basicConfig(
    level=logging.DEBUG,
    format='(%(threadName)-10s) %(message)s',
)

class Counter(object):
    def __init__(self, start=0):
        self.lock = threading.Lock()
        self.value = start
    def increment(self):
        logging.debug('Waiting for lock')
        self.lock.acquire()
        try:
            logging.debug('Acquired lock')
            self.value = self.value + 1
        finally:
            logging.debug("Releasing")
            self.lock.release()

def worker(c):
    print('Entering worker...')
    for i in range(2):
        print('worker loop:', i)
        pause = random.random()
        logging.debug('Sleeping %0.02f', pause)
        time.sleep(pause)
        c.increment()
    logging.debug('Done')

counter = Counter()
for i in range(2):
    t = threading.Thread(target=worker, args=(counter,))
    t.start()

logging.debug('Waiting for worker threads')
main_thread = threading.currentThread()

try:
    for t in threading.enumerate():
        if t is not main_thread:
            t.join()
except Exception as e:
    print('exception: ', e)
finally:
    print('This is test')

logging.debug('Counter: %d', counter.value)

logging.debug('End of script')

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions