Fix deepcopy of shared variable due to a Numpy problem.

The fix is taken from debugmode.
Better fix that would work for more cases if this happen again.

Also fix the test.
pep8
Fix the new deep copy. I was not passing and using correctly the memo.
more consistent call.
Make work around work when readonly is True.
Merge pull request #1864 from nouiz/fix_numpy_deepcopy

Fix deepcopy of shared variable due to a Numpy problem.