Multiprocessing: AttributeError: StdIn instance has no attribute 'close' - python

I get this error with multiprocessing when looping a simple range.
Process PoolWorker-37:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 249, in _bootstrap
sys.stdin.close()
AttributeError: StdIn instance has no attribute 'close'
The code
pool = multiprocessing.Pool(processes=3)
pool.map(get_info, range(20000,20010), 1)
pool.close()
pool.join()
Update
the first issue was by eclipse altering the environment, but now I get this error
PicklingError: Can't pickle <type 'cStringIO.StringO'>: attribute lookup cStringIO.StringO failed

This error is thrown if you are running in PyCharm console. I used the system console and all ran ok.

In PyCharm 4.5 the solution for me was to remove "Show command line afterwards" checkbox in server Run/Debug configuration for python file (which is not even documented in PyCharm manual)

Related

PyCharm Debugger failure with Poetry despite working in Run configuration

I'm attempting to debug a Poetry script (that I didn't write) in PyCharm, but am running into problems with the Debug Configuration.
I am able to run the script without error directly from my bash shell. I used those parameters to set up my Run Configuration, which behaves as I expect. Here's the output from running without the debugger:
/Users/me/Library/Caches/pypoetry/virtualenvs/infra-KKsTCFNL-py3.9/bin/python /Users/me/Projects/infra/bin/my-script -c a_flag
Success!
So far so good; however, when I click debug, I get:
/Users/me/Library/Caches/pypoetry/virtualenvs/infra-KKsTCFNL-py3.9/bin/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --multiproc --client 127.0.0.1 --port 49371 --file /Users/me/Projects/infra/bin/my-script -c a_flag
Connected to pydev debugger (build 212.4746.96)
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 261, in _add_reader
key = self._selector.get_key(fd)
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/selectors.py", line 193, in get_key
raise KeyError("{!r} is not registered".format(fileobj)) from None
KeyError: '6 is not registered'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/selectors.py", line 523, in register
self._selector.control([kev], 0, 0)
TypeError: changelist must be an iterable of select.kevent objects
python-BaseException
Exception ignored in: <function BaseEventLoop.__del__ at 0x10e139820>
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 683, in __del__
self.close()
File "/usr/local/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 63, in close
if self._signal_handlers:
AttributeError: '_UnixSelectorEventLoop' object has no attribute '_signal_handlers'
sys:1: RuntimeWarning: coroutine 'main' was never awaited
Process finished with exit code 1
and here is the minimal my-script
#!/usr/bin/env python3
import asyncio
import sys
async def main():
print("Success!")
if __name__ == "__main__":
sys.exit(asyncio.run(main()))
So the error occurs before ever entering main(). I am somewhat at a loss for appropriate next steps -- is the problem Poetry? My Debug configuration? My interpreter?

Multithreading frozen in Python Spyder but not command prompt Windows 10

I am running a script inside Spyder that utilizes the multithreading library and the IPython console freezes with the output below. However, running the script using Windows command prompt via 'python quickstart11.py' works fine and generates the proper output.
runfile('C:/Python35/User/backtrader-master/docs/quickstart/quickstart11.py', wdir='C:/Python35/User/backtrader-master/docs/quickstart')
Exception in thread Thread-8:
Traceback (most recent call last):
File "C:\Anaconda3\lib\threading.py", line 914, in _bootstrap_inner
self.run()
File "C:\Anaconda3\lib\threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "C:\Anaconda3\lib\multiprocessing\pool.py", line 429, in _handle_results
task = get()
File "C:\Anaconda3\lib\multiprocessing\connection.py", line 251, in recv
return ForkingPickler.loads(buf.getbuffer())
AttributeError: Can't get attribute 'TestStrategy' on <module '__main__' (<_frozen_importlib_external.SourceFileLoader object at 0x000002727C461438>)>
I've tried adding freeze_support() according to Python doc, which should alleviate the problem, but it still freezes. What is going on?
Windows 10 64bit, Anaconda Python 35 64bit installer.
The problem is in Spyder. The kernel is running in interpreted mode and the addition of "freeze_support" doesn't happend before other things even if that's the intention, because the kernel is already running.
See here: https://github.com/mementum/backtrader/issues/118

Attribute Error occurs when performing division in PyCharm 5.0.2

I'm working on a Windows 64-bit machine and using Python 3.4 and PyCharm 5.0.2. I find that PyCharm gives me error even when I'm doing tasks as simple as divisions:
up = 22.33695
down = 1.2598
this = up/down
It gives me this error message:
Error evaluating: thread_id: pid7636_seq2
frame_id: 54197704
scope: FRAME
attrs: this
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 5.0.2\helpers\pydev\pydevd_vars.py", line 238, in resolveCompoundVariable
return resolver.getDictionary(var)
AttributeError: 'NoneType' object has no attribute 'getDictionary'
I really can't understand where I did wrong or if this is a bug in PyCharm. Can you help?

AttributeError:'module' object has no attribute 'call' :Python

I am new to python and not knowing whats going on here. I have tried searching a lot but had to end up asking here
I am trying to learn subprocess which executes a simple command as:
import subprocess
subprocess.call(['ls'])
Now, when I run the program I get this error:
Traceback (most recent call last):
File "subprocess.py", line 1, in <module>
import subprocess
File "/task/subprocess.py", line 2, in <module>
subprocess.call(['ls'])
AttributeError: 'module' object has no attribute 'call'
You called your file subprocess.py, change then name and you will be ok. You are trying to import from your file and not the module
ldap-new:~ # rm -rf subprocess.pyc
This worked for me i just removed .pyc file and run again
Regards,
-Mansur

PyDev debug mode TypeError: 'NoneType' object is not subscriptable'

I am writing a script that uses the logging module to handle the verbosity of the script. I am using the PyDev plugin for Eclipse and running Python 3.2. If I "Run" the script everything works fine, but if I "Debug" the script, I get the following error:
Traceback (most recent call last):
File "C:\Program Files (x86)\Eclipse\eclipse\plugins\org.python.pydev_3.2.0.201312292215\pysrc\pydevd.py", line 1146, in trace_dispatch
filename, base = GetFilenameAndBase(frame)
File "C:\Program Files (x86)\Eclipse\eclipse\plugins\org.python.pydev_3.2.0.201312292215\pysrc\pydevd_file_utils.py", line 224, in GetFilenameAndBase
return NORM_FILENAME_AND_BASE_CONTAINER[f]
TypeError: 'NoneType' object is not subscriptable
I couldn't figure out where the error was coming from, so I started commenting out everything and figured out the statement "import logging" is causing the error. Here's the code I'm running:
import logging
def main():
print("Logging import test")
if __name__ == '__main__':
main()
I've checked to make sure the logging module is with all of the other standard modules in my Python32 install location. Any ideas? Again, this is only when I run PyDev in debug mode; run completes with no errors. Thanks!

Categories