Re: Django Channels 2.0 websocket crashing & blocking while using aiohttp
Further to the message above - I moved everything into the consumers.py file and routed to the class inside of there. Still getting this error AFTER I get the print statement print('awaiting t1') I have confirmed that this occurs after this runs successfully: background worker sends a message to the group -> websocket consumer picks it up at the handler -> handler sends it to the browser -> browser/javascript recieves it and uses the data -> *error below* awaiting t1 ERROR:root:Exception inside application: No handler for message type backgroundWorkerUpdate File "/Users/nate/Dev/projects/Trading/version_control/CryptoArb/tests/lib/python3.6/site-packages/channels/consumer.py", line 54, in __call__ await await_many_dispatch([receive, self.channel_receive], self.dispatch) File "/Users/nate/Dev/projects/Trading/version_control/CryptoArb/tests/lib/python3.6/site-packages/channels/utils.py", line 50, in await_many_dispatch await dispatch(result) File "/Users/nate/Dev/projects/Trading/version_control/CryptoArb/tests/lib/python3.6/site-packages/channels/consumer.py", line 69, in dispatch raise ValueError("No handler for message type %s" % message["type"]) No handler for message type backgroundWorkerUpdate On Monday, June 18, 2018 at 9:33:12 AM UTC-4, itsnate_b wrote: > > Hi Andrew, > Thank you for your quick reply. I use AsyncConsumer in the background > worker because it seems to route properly (i.e. without error). If I create > a new class, then I run into scope issues or simply a TypeError where the > 'backgroundConsumer object is not callable'. *The reason for all of this > is that when I originally had my external websocket code directly inside > consumer.py, it ended up blocking any incoming/outgoing communication > between the AsyncWebsocketConsumer and the browser - probably because, as > you said 'your listen() method is blocking...[because it]listens on it > for messages forever'.* Since I am new to asyncio development, I figured > the best way was to run the external websocket in a background worker, > asynchronously, and then maintain my websocket consumer for dynamic browser > updates - which "works" but apparently not for so long. Is there a better > way to architect this that you suggest? By the way, you've done a terrific > job with channels... > > Here is my routing, so that it's clear what I am doing: > > *routing.py* > > from channels.auth import AuthMiddlewareStack > from channels.routing import ProtocolTypeRouter, URLRouter, > ChannelNameRouter > import dashboard.routing > from dashboard.backgroundUpdater import backgroundConsumer > > application = ProtocolTypeRouter({ > # (http->django views is added by default) > 'websocket': AuthMiddlewareStack( > URLRouter( > dashboard.routing.websocket_urlpatterns > ) > ), > 'channel': ChannelNameRouter({ > "toggle": backgroundConsumer, > }), > }) > > On Sunday, June 17, 2018 at 2:40:12 PM UTC-4, Andrew Godwin wrote: >> >> I'm not quite sure why you seem to be using an AsyncConsumer outside of >> the context of the Channels routing framework? >> >> Anyway, it sounds like from what you're describing that your listen() >> method is blocking, which makes sense, as it connects to an external >> websocket and listens on it for messages forever. Not sure why the crashing >> Channels websocket takes down the client one, but maybe they are both made >> to crash by some third, external, force? >> >> Andrew >> >> On Sun, Jun 17, 2018 at 11:33 AM Nathan Bluvol >> wrote: >> >>> I am using Django 2.0.5, Python 3.6.2, Django Channels 2.1.1, aiohttp >>> 3.1.3. >>> >>> Background: >>> I am connecting to an external websocket, asynchronously, using aiohttp >>> within a background channels worker. Once triggered, the socket connection >>> stays alive, listening/streaming, and sends incoming messages to a consumer >>> through a group_send. The consumer receives it at the appropriate handler, >>> however, after some time, it appears that the channels websocket dies and >>> the handler can no longer be found - I get 'No handler for message >>> type' even though it has been working successfully until that >>> point. Second issue is that 'await t1' seems to block in the background. I >>> route the 'toggle' to backgroundUpdater.py. >>> >>> *consumers.py*: >>> >>> from channels.generic.websocket i
Re: Django Channels 2.0 websocket crashing & blocking while using aiohttp
Further to the message above - I moved everything into the consumers.py file and routed to the class inside of there. Still getting this error AFTER I get the print statement print('awaiting t1') I have confirmed that this occurs after this runs successfully: background worker sends a message to the group -> websocket consumer picks it up at the handler -> handler sends it to the browser -> browser/javascript recieves it and uses the data -> *error below* awaiting t1 ERROR:root:Exception inside application: No handler for message type backgroundWorkerUpdate File ".../lib/python3.6/site-packages/channels/consumer.py", line 54, in __call__ await await_many_dispatch([receive, self.channel_receive], self.dispatch) File ".../lib/python3.6/site-packages/channels/utils.py", line 50, in await_many_dispatch await dispatch(result) File "...lib/python3.6/site-packages/channels/consumer.py", line 69, in dispatch raise ValueError("No handler for message type %s" % message["type"]) No handler for message type backgroundWorkerUpdate On Monday, June 18, 2018 at 9:33:12 AM UTC-4, itsnate_b wrote: > > Hi Andrew, > Thank you for your quick reply. I use AsyncConsumer in the background > worker because it seems to route properly (i.e. without error). If I create > a new class, then I run into scope issues or simply a TypeError where the > 'backgroundConsumer object is not callable'. *The reason for all of this > is that when I originally had my external websocket code directly inside > consumer.py, it ended up blocking any incoming/outgoing communication > between the AsyncWebsocketConsumer and the browser - probably because, as > you said 'your listen() method is blocking...[because it]listens on it > for messages forever'.* Since I am new to asyncio development, I figured > the best way was to run the external websocket in a background worker, > asynchronously, and then maintain my websocket consumer for dynamic browser > updates - which "works" but apparently not for so long. Is there a better > way to architect this that you suggest? By the way, you've done a terrific > job with channels... > > Here is my routing, so that it's clear what I am doing: > > *routing.py* > > from channels.auth import AuthMiddlewareStack > from channels.routing import ProtocolTypeRouter, URLRouter, > ChannelNameRouter > import dashboard.routing > from dashboard.backgroundUpdater import backgroundConsumer > > application = ProtocolTypeRouter({ > # (http->django views is added by default) > 'websocket': AuthMiddlewareStack( > URLRouter( > dashboard.routing.websocket_urlpatterns > ) > ), > 'channel': ChannelNameRouter({ > "toggle": backgroundConsumer, > }), > }) > > On Sunday, June 17, 2018 at 2:40:12 PM UTC-4, Andrew Godwin wrote: >> >> I'm not quite sure why you seem to be using an AsyncConsumer outside of >> the context of the Channels routing framework? >> >> Anyway, it sounds like from what you're describing that your listen() >> method is blocking, which makes sense, as it connects to an external >> websocket and listens on it for messages forever. Not sure why the crashing >> Channels websocket takes down the client one, but maybe they are both made >> to crash by some third, external, force? >> >> Andrew >> >> On Sun, Jun 17, 2018 at 11:33 AM Nathan Bluvol >> wrote: >> >>> I am using Django 2.0.5, Python 3.6.2, Django Channels 2.1.1, aiohttp >>> 3.1.3. >>> >>> Background: >>> I am connecting to an external websocket, asynchronously, using aiohttp >>> within a background channels worker. Once triggered, the socket connection >>> stays alive, listening/streaming, and sends incoming messages to a consumer >>> through a group_send. The consumer receives it at the appropriate handler, >>> however, after some time, it appears that the channels websocket dies and >>> the handler can no longer be found - I get 'No handler for message >>> type' even though it has been working successfully until that >>> point. Second issue is that 'await t1' seems to block in the background. I >>> route the 'toggle' to backgroundUpdater.py. >>> >>> *consumers.py*: >>> >>> from channels.generic.websocket import AsyncWebsocketConsumer >>> import json >>> >>> >>> class MyConsumer(AsyncWebsocketConsumer): >>> >>> async def connect(se
Re: I am trying to create polls project as mentiioned in the django website
I'm assuming you already did this? django-admin startproject mysite If so, then you should have a mysite folder, inside of another mysite folder. Inside of there you should have views.py, models.py. You may need to create the urls.py file, if it's not already there. should look like what is shown in the tutorial... mysite/ manage.py mysite/ __init__.py settings.py urls.py wsgi.py On Monday, June 18, 2018 at 8:26:42 AM UTC-4, Django starter wrote: > > I am trying to create polls project as mentiioned in the django website, i > am a beginer of django, as mentioned in the > https://docs.djangoproject.com/en/dev/intro/tutorial01/ > i dont see mysite/urls.py, do i need to create mysite and urls.py, could > you please let me know. > > Thanks > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2389c312-9fa1-4314-8266-cce998cea3cb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: I am trying to create polls project as mentiioned in the django website
No problem. Good luck! On Monday, June 18, 2018 at 12:46:23 PM UTC-4, Django starter wrote: > > Hi Nathan, > > Appreciate your response, it wasnt there, > > I would create it again and check and thanks a lot for responding > > On Mon, Jun 18, 2018 at 11:43 PM, itsnate_b > wrote: > >> I'm assuming you already did this? >> django-admin startproject mysite >> >> If so, then you should have a mysite folder, inside of another mysite >> folder. Inside of there you should have views.py, models.py. You may need >> to create the urls.py file, if it's not already there. >> >> should look like what is shown in the tutorial... >> >> mysite/ >> manage.py >> mysite/ >> __init__.py >> settings.py >> urls.py >> wsgi.py >> >> >> On Monday, June 18, 2018 at 8:26:42 AM UTC-4, Django starter wrote: >>> >>> I am trying to create polls project as mentiioned in the django website, >>> i am a beginer of django, as mentioned in the >>> https://docs.djangoproject.com/en/dev/intro/tutorial01/ >>> i dont see mysite/urls.py, do i need to create mysite and urls.py, could >>> you please let me know. >>> >>> Thanks >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users...@googlegroups.com . >> To post to this group, send email to django...@googlegroups.com >> . >> Visit this group at https://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/2389c312-9fa1-4314-8266-cce998cea3cb%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/2389c312-9fa1-4314-8266-cce998cea3cb%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b41e988b-e70b-413e-aed6-8ce0d51bc906%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django Channels 2.0 websocket crashing & blocking while using aiohttp
I am unable to determine the cause of the handler issue (assuming something is crashing the channels websocket?). Could this be a redis queue issue? Where events being passed through the channel layer are filling up a queue and not being flushed correctly? I have no idea where to go from here On Monday, June 18, 2018 at 12:05:26 PM UTC-4, itsnate_b wrote: > > Further to the message above - I moved everything into the consumers.py > file and routed to the class inside of there. Still getting this error > AFTER I get the print statement > print('awaiting t1') > > I have confirmed that this occurs after this runs successfully: background > worker sends a message to the group -> websocket consumer picks it up at > the handler -> handler sends it to the browser -> browser/javascript > recieves it and uses the data -> *error below* > > awaiting t1 > > ERROR:root:Exception inside application: No handler for message type > backgroundWorkerUpdate > > File ".../lib/python3.6/site-packages/channels/consumer.py", line 54, in > __call__ > > await await_many_dispatch([receive, self.channel_receive], > self.dispatch) > > File ".../lib/python3.6/site-packages/channels/utils.py", line 50, in > await_many_dispatch > > await dispatch(result) > > File "...lib/python3.6/site-packages/channels/consumer.py", line 69, in > dispatch > > raise ValueError("No handler for message type %s" % message["type"]) > > No handler for message type backgroundWorkerUpdate > > > On Monday, June 18, 2018 at 9:33:12 AM UTC-4, itsnate_b wrote: >> >> Hi Andrew, >> Thank you for your quick reply. I use AsyncConsumer in the background >> worker because it seems to route properly (i.e. without error). If I create >> a new class, then I run into scope issues or simply a TypeError where the >> 'backgroundConsumer object is not callable'. *The reason for all of this >> is that when I originally had my external websocket code directly inside >> consumer.py, it ended up blocking any incoming/outgoing communication >> between the AsyncWebsocketConsumer and the browser - probably because, as >> you said 'your listen() method is blocking...[because it]listens on it >> for messages forever'.* Since I am new to asyncio development, I figured >> the best way was to run the external websocket in a background worker, >> asynchronously, and then maintain my websocket consumer for dynamic browser >> updates - which "works" but apparently not for so long. Is there a better >> way to architect this that you suggest? By the way, you've done a terrific >> job with channels... >> >> Here is my routing, so that it's clear what I am doing: >> >> *routing.py* >> >> from channels.auth import AuthMiddlewareStack >> from channels.routing import ProtocolTypeRouter, URLRouter, >> ChannelNameRouter >> import dashboard.routing >> from dashboard.backgroundUpdater import backgroundConsumer >> >> application = ProtocolTypeRouter({ >> # (http->django views is added by default) >> 'websocket': AuthMiddlewareStack( >> URLRouter( >> dashboard.routing.websocket_urlpatterns >> ) >> ), >> 'channel': ChannelNameRouter({ >> "toggle": backgroundConsumer, >> }), >> }) >> >> On Sunday, June 17, 2018 at 2:40:12 PM UTC-4, Andrew Godwin wrote: >>> >>> I'm not quite sure why you seem to be using an AsyncConsumer outside of >>> the context of the Channels routing framework? >>> >>> Anyway, it sounds like from what you're describing that your listen() >>> method is blocking, which makes sense, as it connects to an external >>> websocket and listens on it for messages forever. Not sure why the crashing >>> Channels websocket takes down the client one, but maybe they are both made >>> to crash by some third, external, force? >>> >>> Andrew >>> >>> On Sun, Jun 17, 2018 at 11:33 AM Nathan Bluvol >>> wrote: >>> >>>> I am using Django 2.0.5, Python 3.6.2, Django Channels 2.1.1, aiohttp >>>> 3.1.3. >>>> >>>> Background: >>>> I am connecting to an external websocket, asynchronously, using aiohttp >>>> within a background channels worker. Once triggered, the socket connection >>>> stays alive, listening/streaming, and sends incoming messages to a >>>>
Re: Django Channels 2.0 websocket crashing & blocking while using aiohttp
I managed to resolve the cascading crash issue by doing some more asyncio reading and using: self.t1 = asyncio.run_coroutine_threadsafe(self.listen(), loop=loop) instead of: t1 = asyncio.ensure_future(self.listen(), loop=loop) await t1 This makes it run concurrently with the main asyncio channels threads. The 'No handler..' error still shows up in the main websocket consumer, but it seems like it doesn't cause an irrecoverable crash AND it's not blocking! *phew*! Would be nice to fix it, but it's not urgent. Now I have an issue with initializing only one background worker versus the current channels implementation of initializing a new class for every routing call. Will post under a separate issue. On Monday, June 18, 2018 at 2:27:57 PM UTC-4, itsnate_b wrote: > > I am unable to determine the cause of the handler issue (assuming > something is crashing the channels websocket?). Could this be a redis queue > issue? Where events being passed through the channel layer are filling up a > queue and not being flushed correctly? I have no idea where to go from > here > > On Monday, June 18, 2018 at 12:05:26 PM UTC-4, itsnate_b wrote: >> >> Further to the message above - I moved everything into the consumers.py >> file and routed to the class inside of there. Still getting this error >> AFTER I get the print statement >> print('awaiting t1') >> >> I have confirmed that this occurs after this runs successfully: >> background worker sends a message to the group -> websocket consumer picks >> it up at the handler -> handler sends it to the browser -> >> browser/javascript recieves it and uses the data -> *error below* >> >> awaiting t1 >> >> ERROR:root:Exception inside application: No handler for message type >> backgroundWorkerUpdate >> >> File ".../lib/python3.6/site-packages/channels/consumer.py", line 54, >> in __call__ >> >> await await_many_dispatch([receive, self.channel_receive], >> self.dispatch) >> >> File ".../lib/python3.6/site-packages/channels/utils.py", line 50, in >> await_many_dispatch >> >> await dispatch(result) >> >> File "...lib/python3.6/site-packages/channels/consumer.py", line 69, in >> dispatch >> >> raise ValueError("No handler for message type %s" % message["type"]) >> >> No handler for message type backgroundWorkerUpdate >> >> >> On Monday, June 18, 2018 at 9:33:12 AM UTC-4, itsnate_b wrote: >>> >>> Hi Andrew, >>> Thank you for your quick reply. I use AsyncConsumer in the background >>> worker because it seems to route properly (i.e. without error). If I create >>> a new class, then I run into scope issues or simply a TypeError where the >>> 'backgroundConsumer object is not callable'. *The reason for all of >>> this is that when I originally had my external websocket code directly >>> inside consumer.py, it ended up blocking any incoming/outgoing >>> communication between the AsyncWebsocketConsumer and the browser - probably >>> because, as you said 'your listen() method is blocking...[because >>> it]listens on it for messages forever'.* Since I am new to asyncio >>> development, I figured the best way was to run the external websocket in a >>> background worker, asynchronously, and then maintain my websocket consumer >>> for dynamic browser updates - which "works" but apparently not for so long. >>> Is there a better way to architect this that you suggest? By the way, >>> you've done a terrific job with channels... >>> >>> Here is my routing, so that it's clear what I am doing: >>> >>> *routing.py* >>> >>> from channels.auth import AuthMiddlewareStack >>> from channels.routing import ProtocolTypeRouter, URLRouter, >>> ChannelNameRouter >>> import dashboard.routing >>> from dashboard.backgroundUpdater import backgroundConsumer >>> >>> application = ProtocolTypeRouter({ >>> # (http->django views is added by default) >>> 'websocket': AuthMiddlewareStack( >>> URLRouter( >>> dashboard.routing.websocket_urlpatterns >>> ) >>> ), >>> 'channel': ChannelNameRouter({ >>> "toggle": backgroundConsumer, >>> }), >>> }) >>> >>> On Sunday, June 17, 2018 at 2:40:12 PM UTC-4, Andrew Godwin wrote: >>>> >>&g
Django Channels 2.0 - How to init and persist/communicate with only one instance of background worker for every channel_layer.send?
I am using Django 2.0.5, Python 3.6.2, Django Channels 2.1.1, aiohttp 3.1.3. I have created a background worker class which is initialized on a route to the appropriate event/function. Problem is that it initializes a *new* instance of the class on every triggered call, meaning that I cannot access contextual variables (they don't persist). Is there a way to trigger the same (i.e. first) and only class repeatedly on each routed call? I can change it all to function calls with global variables stored for the relevant asyncio futures and/or booleans, but would really prefer not to do thatany suggestions? My (simplified) code: *consumers.py* from channels.generic.websocket import AsyncWebsocketConsumer from channels.consumer import AsyncConsumer from channels.layers import get_channel_layer import json import asyncio import aiohttp import datetime class mainConsumer(AsyncWebsocketConsumer): async def connect(self): await self.channel_layer.group_add('myGroup', self.channel_name) await self.accept() async def disconnect(self, closeCode): await self.channel_layer.group_discard('myGroup', self.channel_name) async def receive(self, text_data): eventData = json.loads(text_data) print(eventData) if eventData['toggle'] == 'on': await self.channel_layer.send('myToggle',{"type": "openConnection"}) elif eventData['toggle'] == 'off': await self.channel_layer.send('myToggle',{"type": "closeConnection"}) async def myUpdate(self, data): updateMsg = #some data processing here await self.send(text_data=json.dumps(updateMsg)) class backgroundConsumer(AsyncConsumer): def __init__(self, scope): self.scope = scope self.turnOnListener = True self.channelLayer = get_channel_layer() self.t1 = None print('inside init') # this will print init on every channel_layer.send to 'myToggle' in mainConsumer async def listen(self): async with aiohttp.ClientSession() as session: async with session.ws_connect('...streaming url...', ssl=False) as ws: await ws.send_str('...some string...') async for msg in ws: if msg.type == aiohttp.WSMsgType.TEXT: if msg.data.startswith('2'): await ws.send_str('3') else: await self.parseListenData(msg) async def parseListenData(self, msgContent): # process and create updateMsg dict with type: 'myUpdate' (so that it gets to the myUpdate function in main Consumer) await self.channelLayer.group_send('myGroup', updateMsg) async def openConnection(self, event): if(self.turnOnListener): *# THIS IS ALWAYS TRUE BECAUSE THE ROUTE INITIALIZES A NEW INSTANCE OF THIS CLASS!!* await self.channelLayer.group_add( 'myGroup', self.channel_name, ) self.turnOnListener = False # This only changes it for the current instance (obviously) loop = asyncio.get_event_loop() self.t1 = asyncio.run_coroutine_threadsafe(self.listen(), loop=loop) else: print('already turned on listener') async def closeConnection(self, event): loop = asyncio.get_event_loop() loop.call_soon_threadsafe(self.t1.cancel) *# t1 is always None because the route initialized a new instance of this class!!* *routing.py* from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter, ChannelNameRouter import dashboard.routing from dashboard.consumers import backgroundConsumer application = ProtocolTypeRouter({ # (http->django views is added by default) 'websocket': AuthMiddlewareStack( URLRouter( dashboard.routing.websocket_urlpatterns ) ), 'channel': ChannelNameRouter({ "myToggle": backgroundConsumer, }), }) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/431ada54-74cb-4822-9b33-5dcb0326fb9c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: I am trying to create polls project as mentiioned in the django website
Syed, I really suggest you follow the Django Tutorial found here: https://docs.djangoproject.com/en/2.0/intro/tutorial01/ Go through *all* of the parts of the tutorial (there are 7 parts), line by line. Start with a completely new project. Jumping in and out of other tutorials is really not recommended (my 2 cents). I followed through all parts of the tutorial when I first started and found it to be a really great starting point. The documentation is very well written. I really can't help you if you are jumping around between different sites/tutorials. Start one and follow through all the way to the end. Good luck! On Tuesday, June 19, 2018 at 7:14:13 AM UTC-4, Django starter wrote: > > Hi Nathan, > > I am really confused starting up with my website > > i have gone through couple of Videos and sites to start with, > in one of the sites, it was mentioned to make changes in urls.py and then > in views.py and in settings.py [Installed Apps] to have the site worked. > > unfortunately i dont see views.py > > below is the tree > > (el) ssyed@ssyed:~/el/bin$ tree > . > ├── activate > ├── activate.csh > ├── activate.fish > ├── activate_this.py > ├── chardetect > ├── django-admin > ├── django-admin.py > ├── easy_install > ├── easy_install-3.6 > ├── elastic > │ ├── db.sqlite3 > │ ├── DJango > │ ├── elastic > │ │ ├── __init__.py > │ │ ├── __pycache__ > │ │ │ ├── __init__.cpython-36.pyc > │ │ │ ├── settings.cpython-36.pyc > │ │ │ ├── urls.cpython-36.pyc > │ │ │ └── wsgi.cpython-36.pyc > │ │ ├── settings.py > │ │ ├── urls.py > │ │ └── wsgi.py > │ └── manage.py > > > Could you please help me know if i am going in the right way. > > Thanks > SYED > > > On Mon, Jun 18, 2018 at 11:50 PM, itsnate_b > wrote: > >> No problem. Good luck! >> >> On Monday, June 18, 2018 at 12:46:23 PM UTC-4, Django starter wrote: >>> >>> Hi Nathan, >>> >>> Appreciate your response, it wasnt there, >>> >>> I would create it again and check and thanks a lot for responding >>> >>> On Mon, Jun 18, 2018 at 11:43 PM, itsnate_b wrote: >>> >>>> I'm assuming you already did this? >>>> django-admin startproject mysite >>>> >>>> If so, then you should have a mysite folder, inside of another mysite >>>> folder. Inside of there you should have views.py, models.py. You may need >>>> to create the urls.py file, if it's not already there. >>>> >>>> should look like what is shown in the tutorial... >>>> >>>> mysite/ >>>> manage.py >>>> mysite/ >>>> __init__.py >>>> settings.py >>>> urls.py >>>> wsgi.py >>>> >>>> >>>> On Monday, June 18, 2018 at 8:26:42 AM UTC-4, Django starter wrote: >>>>> >>>>> I am trying to create polls project as mentiioned in the django >>>>> website, i am a beginer of django, as mentioned in the >>>>> https://docs.djangoproject.com/en/dev/intro/tutorial01/ >>>>> i dont see mysite/urls.py, do i need to create mysite and urls.py, >>>>> could you please let me know. >>>>> >>>>> Thanks >>>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Django users" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to django-users...@googlegroups.com. >>>> To post to this group, send email to django...@googlegroups.com. >>>> Visit this group at https://groups.google.com/group/django-users. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/django-users/2389c312-9fa1-4314-8266-cce998cea3cb%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/django-users/2389c312-9fa1-4314-8266-cce998cea3cb%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users...@googlegroups.com . >> To post to this group, send email to django...@googlegroups.com >> . >
Re: channels 2 message type handler in different consumer
Post some code please and I can try to help. On Tuesday, June 19, 2018 at 11:21:31 AM UTC-4, ILia Hopa wrote: > > hello! is it possible to set the handler of the group message in the > different consumer (from the one from which message was dispatched). > > ex: I have 2 consumers: `cli0consumer` and `cli1consumer`. there is a > method in a class called from `cli0consumer` which is sending a message to > the group 'group0' with the type 'msg.action'. if the handler 'msg_action' > is in 'cli1consumer' - its not called. however I want to pass it to client > connected to 'cli1consumer'. > > how can I solve it? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/821381a7-1ea6-47d7-8f8a-6f7b2b4039f7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: channels 2 message type handler in different consumer
can you please show what's in your routing.py? How are you routing to command_status_all? On Tuesday, June 19, 2018 at 4:01:32 PM UTC-4, ILia Hopa wrote: > > Here, relevant code: > Want a clients connected to Cli0Consumer to receive a message. > > class Cli0Consumer(JsonWebsocketConsumer): > def connect(self): > try: > async_to_sync(self.channel_layer.group_add)("cli0-group", > "custom_channel_name") > except Exception as e: > logging.error(sys.exc_info()[0]) > > self.accept() > > def command_status_all(self, event): > logger.info(event) > self.send_json(event["message"]) > > > class Cli1Consumer(JsonWebsocketConsumer): > def connect(self): > self.accept() > async_to_sync(self.channel_layer.group_add)(_group_name("cli1-group", > self.channel_name) > > #async_to_sync(self.channel_layer.group_add)(_group_name("cli0-group", > self.channel_name) - tried with and without subscribing to cli0-group > > def receive_json(self, content, **kwargs): > group_name = _group_name(self.scope['user'], 'web') > logger.info("received: {}".format(content)) > > with SomeService("cli1-group") as monitor: > monitor.watch_message(content=content) > > > class SomeService(object): > def __enter__(self): > return self > > > def __init__(self, group_name): > self.cli1_group = group_name > self.cli0_group = group_name.replace('cli1', 'cli0') > > def watch_message(self, content): >async_to_sync(channel_layer.group_send)( > self.cli0_group, > { > "type": "command.status.all", > "message": jsonpickle.encode(msg), > }, >) > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f8cb5319-1242-4d05-8393-56eb1f96ce61%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: I am trying to create polls project as mentiioned in the django website
Hi Syed, Take a look at this part of the error: File "/home/ssyed/polls/bin/mysite/mysite/urls.py", line 20, in path('polls/', include('polls.urls')), NameError: name 'include' is not defined It appears that you have missed the addition of 'include' in your urls.py file. The tutorial shows the following, below - does this match your urls.py file contents? Note the line *from django.urls import include, path* >From the tutorial: The next step is to point the root URLconf at the polls.urls module. In mysite/urls.py, add an import for django.urls.include and insert an include() <https://docs.djangoproject.com/en/2.0/ref/urls/#django.urls.include> in the urlpatterns list, so you have: mysite/urls.py from django.contrib import adminfrom django.urls import include, path urlpatterns = [ path('polls/', include('polls.urls')), path('admin/', admin.site.urls),] On Wednesday, June 20, 2018 at 5:12:49 AM UTC-4, Django starter wrote: > > Hi, > > I have tried my best to do this as good as possible, but i still > encountered the error. > > *ERROR :* > > (polls) ssyed@ssyed:~/polls/bin/mysite$ python manage.py runserver > Performing system checks... > > Unhandled exception in thread started by check_errors..wrapper at 0x7f996a794598> > Traceback (most recent call last): > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/utils/autoreload.py", > line 225, in wrapper > fn(*args, **kwargs) > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/core/management/commands/runserver.py", > > line 120, in inner_run > self.check(display_num_errors=True) > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/core/management/base.py", > > line 364, in check > include_deployment_checks=include_deployment_checks, > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/core/management/base.py", > > line 351, in _run_checks > return checks.run_checks(**kwargs) > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/core/checks/registry.py", > > line 73, in run_checks > new_errors = check(app_configs=app_configs) > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/core/checks/urls.py", > line 13, in check_url_config > return check_resolver(resolver) > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/core/checks/urls.py", > line 23, in check_resolver > return check_method() > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/urls/resolvers.py", > line 399, in check > for pattern in self.url_patterns: > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/utils/functional.py", > line 36, in __get__ > res = instance.__dict__[self.name] = self.func(instance) > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/urls/resolvers.py", > line 540, in url_patterns > patterns = getattr(self.urlconf_module, "urlpatterns", > self.urlconf_module) > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/utils/functional.py", > line 36, in __get__ > res = instance.__dict__[self.name] = self.func(instance) > File > "/home/ssyed/polls/lib/python3.6/site-packages/django/urls/resolvers.py", > line 533, in urlconf_module > return import_module(self.urlconf_name) > File "/home/ssyed/polls/lib/python3.6/importlib/__init__.py", line 126, > in import_module > return _bootstrap._gcd_import(name[level:], package, level) > File "", line 994, in _gcd_import > File "", line 971, in _find_and_load > File "", line 955, in > _find_and_load_unlocked > File "", line 665, in _load_unlocked > File "", line 678, in exec_module > File "", line 219, in > _call_with_frames_removed > File "/home/ssyed/polls/bin/mysite/mysite/urls.py", line 20, in > path('polls/', include('polls.urls')), > NameError: name 'include' is not defined > > > > *TREE STRUCTURE : * > > (polls) ssyed@ssyed:~/polls/bin/mysite$ tree > . > ├── db.sqlite3 > ├── manage.py > ├── mysite > │ ├── __init__.py > │ ├── __pycache__ > │ │ ├── __init__.cpython-36.pyc > │ │ ├── settings.cpython-36.pyc > │ │ ├── urls.cpython-36.pyc > │ │ └── wsgi.cpython-36.pyc > │ ├── settings.py > │ ├── urls.py > │ └── wsgi.py > └── polls > ├── admin.py > ├── apps.py > ├── __init__.py > ├── migrations >
Re: Django Channels 2.0 - How to init and persist/communicate with only one instance of background worker for every channel_layer.send?
I am only using one channel name and my expectation is that only one instance of the background worker class should be initiated/used. Instead, I am seeing a new class being initiated for each call routed to the background worker class. This is unexpected... On Thursday, June 21, 2018 at 3:55:23 PM UTC-4, Andrew Godwin wrote: > > The worker server tries to keep one application instance open per incoming > channel name, but that's no guarantee. It will always make a new instance > for different channel names. What kind of behaviour are you expecting? > > Andrew > > On Tue, Jun 19, 2018 at 6:45 AM itsnate_b > wrote: > >> I am using Django 2.0.5, Python 3.6.2, Django Channels 2.1.1, aiohttp >> 3.1.3. >> >> I have created a background worker class which is initialized on a route >> to the appropriate event/function. Problem is that it initializes a *new* >> instance of the class on every triggered call, meaning that I cannot access >> contextual variables (they don't persist). Is there a way to trigger the >> same (i.e. first) and only class repeatedly on each routed call? I can >> change it all to function calls with global variables stored for the >> relevant asyncio futures and/or booleans, but would really prefer not to do >> thatany suggestions? >> >> My (simplified) code: >> >> *consumers.py* >> >> from channels.generic.websocket import AsyncWebsocketConsumer >> from channels.consumer import AsyncConsumer >> from channels.layers import get_channel_layer >> import json >> import asyncio >> import aiohttp >> import datetime >> >> >> class mainConsumer(AsyncWebsocketConsumer): >> >> async def connect(self): >> await self.channel_layer.group_add('myGroup', self.channel_name) >> await self.accept() >> >> async def disconnect(self, closeCode): >> await self.channel_layer.group_discard('myGroup', >> self.channel_name) >> >> async def receive(self, text_data): >> eventData = json.loads(text_data) >> print(eventData) >> if eventData['toggle'] == 'on': >> await self.channel_layer.send('myToggle',{"type": >> "openConnection"}) >> elif eventData['toggle'] == 'off': >> await self.channel_layer.send('myToggle',{"type": >> "closeConnection"}) >> >> async def myUpdate(self, data): >> updateMsg = #some data processing here >> await self.send(text_data=json.dumps(updateMsg)) >> >> >> class backgroundConsumer(AsyncConsumer): >> >> def __init__(self, scope): >> self.scope = scope >> self.turnOnListener = True >> self.channelLayer = get_channel_layer() >> self.t1 = None >> print('inside init') # this will print init on every >> channel_layer.send to 'myToggle' in mainConsumer >> >> async def listen(self): >> >> async with aiohttp.ClientSession() as session: >> async with session.ws_connect('...streaming url...', >> ssl=False) as ws: >> await ws.send_str('...some string...') >> async for msg in ws: >> if msg.type == aiohttp.WSMsgType.TEXT: >> if msg.data.startswith('2'): >> await ws.send_str('3') >> else: >> await self.parseListenData(msg) >> >> async def parseListenData(self, msgContent): >> # process and create updateMsg dict with type: 'myUpdate' (so >> that it gets to the myUpdate function in main Consumer) >> await self.channelLayer.group_send('myGroup', updateMsg) >> >> async def openConnection(self, event): >> if(self.turnOnListener): *# THIS IS ALWAYS TRUE BECAUSE THE >> ROUTE INITIALIZES A NEW INSTANCE OF THIS CLASS!!* >> await self.channelLayer.group_add( >> 'myGroup', >> self.channel_name, >> ) >> self.turnOnListener = False # This only changes it for the >> current instance (obviously) >> loop = asyncio.get_event_loop() >> self.t1 = asyncio.run_coroutine_threadsafe(self.listen(), >> loop=loop) >> else: >>
Django Channels - core.py error
I have the latest Django (2x), channels (2x), and redis/docker as of Aug 31st, 2018 installed. I am encountering a django channels error and have no idea why this is happening...has anyone seen this output? What is the potential cause? Feeling pretty stuck with the error below...happens when refreshing the site and an attempt is made to connect from js Websocket to the python/channels backend. 2018-08-31 15:13:04,623 - ERROR - server - Exception inside application: File "/.../tests/lib/python3.6/site-packages/channels/sessions.py", line 175, in __call__ return await self.inner(receive, self.send) File "/.../tests/lib/python3.6/site-packages/channels/middleware.py", line 41, in coroutine_call await inner_instance(receive, send) File "/.../tests/lib/python3.6/site-packages/channels/consumer.py", line 54, in __call__ await await_many_dispatch([receive, self.channel_receive], self.dispatch) File "/.../tests/lib/python3.6/site-packages/channels/utils.py", line 57, in await_many_dispatch await task File "/.../tests/lib/python3.6/site-packages/channels_redis/core.py", line 400, in receive assert not self.receive_lock.locked() [2018/08/31 15:13:04] WebSocket DISCONNECT /ws/dashboard/ [127.0.0.1:56102] -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dc2a8aa4-ba28-4e90-b66a-8721f5573abf%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django Channels - core.py error
Hi Marius, Thanks for the recommendation. Yes, I am using channel layers outside of consumers, however, this has not been an issue in the past. I am not clear on what you mean by "virtualenv best practices"? Yes, this is running in a venv, and it has worked in the past. I do think this issue is somehow driven by my setup..although any suggestions are welcome! My setup: app1/ ...AsyncWebsocketConsumer (consumers.py) ...AsyncConsumer (backgroundTask.py) ..a couple other function files that call the get_channel_layer to send to a group app2/ ...same idea On Saturday, September 1, 2018 at 9:40:10 AM UTC-4, Marius Räsener wrote: > > Hey, my guess is to check redis integration, f.e. like mentioned here at > the bottom (outside of consumers): > https://channels.readthedocs.io/en/latest/topics/channel_layers.html > > next guess, since an unintended lock feels rather basic to me is to make > sure you‘re still following the virtualenv best practices? No Idea if > that’s worth mentioning or already clear but to be sure... > > Good luck -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/de71f291-c34d-44d9-a68d-ce8420ca9bb3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django Channels - core.py error
I do not think it is even getting to the point where I can accept the connection from within the consumers.pyand I'm not sure how to get a better traceback than the one I already provided. On Saturday, September 1, 2018 at 1:20:16 PM UTC-4, itsnate_b wrote: > > > Hi Marius, > Thanks for the recommendation. Yes, I am using channel layers outside of > consumers, however, this has not been an issue in the past. I am not clear > on what you mean by "virtualenv best practices"? Yes, this is running in a > venv, and it has worked in the past. I do think this issue is somehow > driven by my setup..although any suggestions are welcome! > > My setup: > app1/ > ...AsyncWebsocketConsumer (consumers.py) > ...AsyncConsumer (backgroundTask.py) > ..a couple other function files that call the get_channel_layer to send to > a group > app2/ > ...same idea > > On Saturday, September 1, 2018 at 9:40:10 AM UTC-4, Marius Räsener wrote: >> >> Hey, my guess is to check redis integration, f.e. like mentioned here at >> the bottom (outside of consumers): >> https://channels.readthedocs.io/en/latest/topics/channel_layers.html >> >> next guess, since an unintended lock feels rather basic to me is to make >> sure you‘re still following the virtualenv best practices? No Idea if >> that’s worth mentioning or already clear but to be sure... >> >> Good luck > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/945d172f-d505-4175-90e1-c4ccc5c53a9d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django Channels - core.py error
Turns out there was an erroneous *init* function in the AsyncWebsocketConsumer class. Removing it fixed the issue. On Saturday, September 1, 2018 at 1:23:10 PM UTC-4, itsnate_b wrote: > > I do not think it is even getting to the point where I can accept the > connection from within the consumers.pyand I'm not sure how to get a > better traceback than the one I already provided. > > On Saturday, September 1, 2018 at 1:20:16 PM UTC-4, itsnate_b wrote: >> >> >> Hi Marius, >> Thanks for the recommendation. Yes, I am using channel layers outside of >> consumers, however, this has not been an issue in the past. I am not clear >> on what you mean by "virtualenv best practices"? Yes, this is running in a >> venv, and it has worked in the past. I do think this issue is somehow >> driven by my setup..although any suggestions are welcome! >> >> My setup: >> app1/ >> ...AsyncWebsocketConsumer (consumers.py) >> ...AsyncConsumer (backgroundTask.py) >> ..a couple other function files that call the get_channel_layer to send >> to a group >> app2/ >> ...same idea >> >> On Saturday, September 1, 2018 at 9:40:10 AM UTC-4, Marius Räsener wrote: >>> >>> Hey, my guess is to check redis integration, f.e. like mentioned here at >>> the bottom (outside of consumers): >>> https://channels.readthedocs.io/en/latest/topics/channel_layers.html >>> >>> next guess, since an unintended lock feels rather basic to me is to make >>> sure you‘re still following the virtualenv best practices? No Idea if >>> that’s worth mentioning or already clear but to be sure... >>> >>> Good luck >> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/13c23da8-97ba-4cf1-a4bc-31426e1faf1e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django Channels - core.py error
Hi Simon, Sorry to hear that you are having the same problem! Channels can be a blessing and a curse. I find it very finicky with very poor documentation & poor error handling. As for the fix: I had an AsyncWebsocketConsumer class in consumers.py within which I had a custom __init__ function. I believe I was setting the scope incorrectly within the init. I realized that I had no need to override/augment the init and removed it. The result was that the error disappeared. That was it for me. I have since updated to all the latest builds for the channels & redis infrastructure. Hope that helps. Cheers, Nathan On Tuesday, October 9, 2018 at 9:59:33 AM UTC-4, Simon Vézina wrote: > > Hi itsnate_b, > > Would you mind elaborating on your fix? > > I'm getting this exact error and I'm at a complete loss. Everything > works fine in local, but on my live server, after a couple of minutes/hours > of working fine, I start getting this error in the logs. > > Thanks! > > Le dimanche 2 septembre 2018 13:26:29 UTC-4, itsnate_b a écrit : >> >> Turns out there was an erroneous *init* function in the >> AsyncWebsocketConsumer class. Removing it fixed the issue. >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/228e579c-7967-4024-af57-fcf5ff7c10ca%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.