Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

do not create thread if tests_per_worker==1 #96

Open
tovmeod opened this issue Apr 6, 2021 · 0 comments
Open

do not create thread if tests_per_worker==1 #96

tovmeod opened this issue Apr 6, 2021 · 0 comments

Comments

@tovmeod
Copy link

tovmeod commented Apr 6, 2021

I have some tests using signal and I get"
`
signalnum = <Signals.SIGINT: 2>
handler =

@_wraps(_signal.signal)
def signal(signalnum, handler):
  handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))

E ValueError: signal only works in main thread`

To solve this I propose to not use a ThreadWorker if tests_per_worker==1 and just run it directly
we can use the following instead of process_with_threads:

`
def process_with_one_thread(config, queue, session, tests_per_worker, errors):
# This function will be called from subprocesses, forked from the main
# pytest process. First thing we need to do is to change config's value
# so we know we are running as a worker.
config.parallel_worker = True

	pickling_support.install()
      while True:
          try:
              index = queue.get()
              if index == 'stop':
                  queue.task_done()
                  break
          except ConnectionRefusedError:
              time.sleep(.1)
              continue
          item = session.items[index]
          try:
              pytest_parallel.run_test(session, item, None)
          except BaseException:
              import pickle
              import sys
  
              errors.put(('name', pickle.dumps(sys.exc_info())))
          finally:
              try:
                  queue.task_done()
              except ConnectionRefusedError:
                  pass

`

tovmeod added a commit to tovmeod/pytest-parallel that referenced this issue Apr 26, 2021
andrea-segalini pushed a commit to andrea-segalini/pytest-parallel that referenced this issue Feb 13, 2024
Avoid creating a thread when there is one worker. This allows
benefitting from signal-based communication with the test workers when
threads are not used (e.g., for timeouts as in solves
kevlened#96)
andrea-segalini pushed a commit to andrea-segalini/pytest-parallel that referenced this issue Feb 13, 2024
Avoid creating a thread when there is one worker. This allows
benefitting from signal-based communication with the test workers when
threads are not used (e.g., for timeouts as in solves
kevlened#96)
andrea-segalini pushed a commit to andrea-segalini/pytest-parallel that referenced this issue Feb 13, 2024
Avoid creating a thread when there is one worker. This allows
benefitting from signal-based communication with the test workers when
threads are not used (e.g., for timeouts as in solves
kevlened#96)
andrea-segalini pushed a commit to andrea-segalini/pytest-parallel that referenced this issue Feb 13, 2024
Avoid creating a thread when there is one worker. This allows
benefitting from signal-based communication with the test workers when
threads are not used (e.g., for timeouts as in solves
kevlened#96)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant