Pickle error when running tests for ChannelsLiveServerTestCase for Windows
See original GitHub issueI was following a tutorial, and I’ve been getting AttributeError: Can't pickle local object 'DaphneProcess.__init__.<locals>.<lambda>'
.
I’ve done further research into this and it turns out to be a problem with Python’s multiprocessing
library with lambdas on Windows. There’s a solution on Stack Overflow but changing code in the standard library is not very maintainable.
I went back to the testing code and stripped away all the test cases and just put one test case. I think this is a problem during the server setup. Here’s the code:
from channels.testing import ChannelsLiveServerTestCase
class ChatTests(ChannelsLiveServerTestCase):
serve_static = True
def test_1(self):
self.assertTrue(True)
Are there any other alternatives or solutions to this?
Traceback:
ERROR: test_1 (chat.tests.ChatTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\ederi\Documents\projects\django_chat_project\venv\lib\site-packages\django\test\testcases.py", line 270, in _setup_and_call
self._pre_setup()
File "C:\Users\ederi\Documents\projects\django_chat_project\venv\lib\site-packages\channels\testing\live.py", line 52, in _pre_setup
self._server_process.start()
File "C:\Users\ederi\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "C:\Users\ederi\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\ederi\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Users\ederi\AppData\Local\Programs\Python\Python37\lib\multiprocessing\popen_spawn_win32.py", line 89, in __init__
reduction.dump(process_obj, to_child)
File "C:\Users\ederi\AppData\Local\Programs\Python\Python37\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'DaphneProcess.__init__.<locals>.<lambda>'
----------------------------------------------------------------------
Ran 0 tests in 0.024s
FAILED (errors=1)
Destroying test database for alias 'default'...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\ederi\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\ederi\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
EOFError: Ran out of input
OS: Windows 10 Using: Django 3.1, channels 2.4.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Pickle error when running tests for ChannelsLiveServerTestCase for ...
I've done further research into this and it turns out to be a problem with Python's multiprocessing library with lambdas on Windows. There's...
Read more >Getting a "Can't pickle local object 'LiveServerTestCase'" error ...
I'm developing on Windows, so from what I could tell I'm kinda out of ... I tried running the tests there and it...
Read more >cant get selenium to work i want to test my django channels ...
im trying to test my app and even if i do the most basic things my selenium refuses to work all i get...
Read more >Testing — Channels 4.0.0 documentation
Testing ¶. Testing Channels consumers is a little trickier than testing normal Django views due to their underlying asynchronous nature. To help with...
Read more >django-channels-jwt-auth-middleware - PyPI
I have tried testing the middleware through ChannelsLiveServerTestCase , but currently this does not run due to pickle error in ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems like this is no small issue, what do you suggest for the time being?
OS:
macOS BigSur 11.2.3
Python:3.9.1
Channels:3.0.3
Django:3.2.3
I’m going to close this as a duplicate of #1207 to focus there.