What is the reason of this errror: "PermissionError: [WinError 5] Access is denied"

Viewed 3997

I try to run this example code on Pycharm2018.3.3, it didn't work out. But the same code can run on the IDLE without any error.

My environment is Python3.7 + windows10.

from multiprocessing import Process, Queue

def f(q):
    q.put([42, None, 'hello'])

if __name__ == '__main__':
    q = Queue()
    p = Process(target=f, args=(q,))
    p.start()
    print(q.get())    # prints "[42, None, 'hello']"
    p.join()
Process Process-1:
Traceback (most recent call last):
  File "C:\Users\WYM\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\process.py", line 297, in _bootstrap
    self.run()
  File "C:\Users\WYM\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "E:\Spider2\ControlNode\test.py", line 4, in f
    q.put([42, None, 'hello'])
  File "C:\Users\WYM\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\queues.py", line 82, in put
    if not self._sem.acquire(block, timeout):
PermissionError: [WinError 5] Access is denied.
1 Answers

This issue may be a known bug with Python 3.7.2

I was experiencing the same issue and fixed it by creating a new virtual environment with Python 3.7.0

Related