-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple sessions #666
Comments
You should find asyncore out correctly and use it to get the good result! |
Hi @emamirazavi That's amazing, it's really working the way you suggested! Thanks a lot! I come from a Java world, and I'm very familiar with multi-thread applications... But I'm just trying to figure it out how the Python world works. And I can tell you, it's not so easy to understand and start coding low level functions. I've got this exception every time I restarted the application, I think it's related to some kind of synchronization, but I'm not sure how to start digging about that. Could you please help me?
File "/usr/lib/python2.7/asyncore.py", line 216, in loop |
Probably this exception reads when you stop(terminate) your code. Does it? On Tue, Mar 3, 2015 at 6:34 AM, Rodrigo Freitas notifications@github.com
|
No, it's just after the start... |
Where do you use asyncore.loop?! You should use in a thread import threading loop_thread = threading.Thread(target=asyncore.loop, name="Asyncore @see On Tue, Mar 3, 2015 at 7:06 AM, Rodrigo Freitas notifications@github.com
|
If in your view, everything is okay, what just stays suspicious is your On Tue, Mar 3, 2015 at 7:10 AM, S.Mohammad Emami Razavi <
|
Hmm, I did the changes you suggested, but the error is still happening. Thanks for the help |
@rdiasfreitas did it work out with you? |
@rdiasfreitas @emamirazavi does this work? I've implemented the stuff mentioned here but its unstable. each thread disconnects the other... any solution? |
it works! i moved all my multi-threaded code to asyncore and it is working now. |
@yniv Can you give any specifics about your solution? I've tried the following solution: def login(self): self.logger.debug("CLIENT: Iniciando login para %s", self.credentials) self.layer.init() self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)) try: self.stack.loop() except (KeyboardInterrupt, SystemExit): self.logger.error("CLIENT: Interrupcao forcada") return False except AuthError as e: self.logger.error("CLIENT: Erro de autenticacao!\n%s", e.message) # Desabilita o telefone self.disable_sender() return False def call(self, method, params): return self.layer.call(method, params) The I call login method in a thread: t[sender.id] = threading.Thread(target=stack_list[sender.id].login) t[sender.id].daemon = True t[sender.id].start() Calling the call method still producess the error: stack_list[recipient.sender.id].call( 'message_send', [recipient.get_full_phone(), campaign.message] ) This code still producess the error: Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File "/vagrant/web/src/djyowsup/client/stack.py", line 61, in login self.stack.loop() File "/home/vagrant/.virtualenvs/plataforma_marketing_web/src/yowsup2/yowsup/stacks/yowstack.py", line 195, in loop asyncore.loop(*args, **kwargs) File "/usr/lib/python2.7/asyncore.py", line 216, in loop poll_fun(timeout, map) File "/usr/lib/python2.7/asyncore.py", line 156, in poll read(obj) File "/usr/lib/python2.7/asyncore.py", line 87, in read obj.handle_error() File "/usr/lib/python2.7/asyncore.py", line 83, in read obj.handle_read_event() File "/usr/lib/python2.7/asyncore.py", line 449, in handle_read_event self.handle_read() File "/home/vagrant/.virtualenvs/plataforma_marketing_web/src/yowsup2/yowsup/layers/network/layer.py", line 85, in handle_read data = self.recv(readSize) File "/usr/lib/python2.7/asyncore.py", line 387, in recv data = self.socket.recv(buffer_size) error: [Errno 11] Resource temporarily unavailable |
Can you give more details regarding the loop in asyncore ? Thank you! |
@FunnyBones hope that helps. ask me specific questions and i'll try to help more. |
@yniv thanks for the reply. I want to implement 2 numbers receiving messages in the same time. Unfortunately, I cannot come up with the flow for this. Can you guide me ? |
Yowstack constructor does this. For each client you must call yowstack
|
Can you post a small piece of c9de where you connect 2 clients ? Thabk you! |
How do you start more than one stack and NOT call asyncore.loop more than once? |
Alex, please search for asyncore.loop in Yowsup. Finally it will be found see this file: you must not call YowStack.loop and you should pay attention that asyncore see this file: Give me a feedback. On Sat, Dec 19, 2015 at 6:04 PM, Alex notifications@github.com wrote:
|
Hi, here is how I did it. I added the following lines on line 198 of yowstack.py
It creates one thread for each loop. You can call it like this from the stack:
With this approach I have been able to create several threads, one for each line. But when I run disconnect() from the layer, asyncore fails with a 'Bad File Descriptor' error for one of the threads and all other threads disconnect. |
And even then, I still get a [Errno 11] Resource temporarily unavailable, after a few minutes |
I am planning to implement something similar. (Running different numbers on different threads) I am planning to modify the dispatcher to implement this. I'll keep you guys updated if it works. |
Victor, asyncore itself supports multiple sessions, it can handle over
|
I understand you. So in essence I can have three or more different stacks created under one thread and instead of calling the stack.loop of each stack, I call the asyncore.loop and they will work perfectly?? |
You can instantiate several stacks in single thread and don't call On Wed, Dec 30, 2015 at 3:41 AM, Victor Otieno notifications@github.com
|
Thank you so much for your feedback. Dude you are a life saver. Let me do just that and I will get back to you with the results. |
This is what I have tried: def stackInitiator():
stack1 = YowStack(layers)
stack2 = YowStack(layers)
stack1.setCredentials(CREDENTIALS1)
stack2.setCredentials(CREDENTIALS2)
stack1.broadcastEvent(
YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
stack2.broadcastEvent(
YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
thread = threading.Thread(target=stackInitiator)
thread.start()
asyncore.loop(timeout=1.0) and here is the output: DEBUG:yowsup.stacks.yowstack:Initializing stack
DEBUG:yowsup.stacks.yowstack:Constructed Network Layer
DEBUG:yowsup.stacks.yowstack:Constructed Stanza Regulator Layer
DEBUG:yowsup.stacks.yowstack:Constructed Crypt Layer
DEBUG:yowsup.stacks.yowstack:Constructed Coder Layer
DEBUG:yowsup.stacks.yowstack:Constructed Logger Layer
DEBUG:yowsup.stacks.yowstack:Constructed Axolotl Layer
DEBUG:yowsup.stacks.yowstack:Constructed Authentication Layer - Messages Layer - Receipt Layer - Iq Layer - Ack Layer
DEBUG:yowsup.stacks.yowstack:Constructed Interface Layer
DEBUG:yowsup.stacks.yowstack:Initializing stack
DEBUG:yowsup.stacks.yowstack:Constructed Network Layer
DEBUG:yowsup.stacks.yowstack:Constructed Stanza Regulator Layer
DEBUG:yowsup.stacks.yowstack:Constructed Crypt Layer
DEBUG:yowsup.stacks.yowstack:Constructed Coder Layer
DEBUG:yowsup.stacks.yowstack:Constructed Logger Layer
DEBUG:yowsup.stacks.yowstack:Constructed Axolotl Layer
DEBUG:yowsup.stacks.yowstack:Constructed Authentication Layer - Messages Layer - Receipt Layer - Iq Layer - Ack Layer
DEBUG:yowsup.stacks.yowstack:Constructed Interface Layer
DEBUG:yowsup.layers.network.layer:Connecting to e9.whatsapp.net:443
DEBUG:yowsup.layers.network.layer:Connecting to e9.whatsapp.net:443 No error...It just stops.. |
Victor, it's better you postpone some seconds to trigger connect event On Thu, Dec 31, 2015 at 2:10 PM, Victor Otieno notifications@github.com
|
Ok.. Updating it with your recommendations. |
problem is how to add layers after the core.loop? |
Hi, I have created an http interface project that uses telegram bot api to communicate through whatsapp using yowsup. You can check it out here. Unfortunately, I am having big trouble in connecting with several accounts simultaneously. In fact, I have resorted to using different docker containers, one for each account. I wonder if you can check it out and let me know how to make several accounts run in the same container. |
I got it working with a very simple solution:
It is very easy to use:
|
I have tried a similar solution, but the code after |
I could make it work for multiple lines, but had to comment out line 33 in
This line was blocking the code, preventing other lines to connect to Whatsapp. |
buenas, intento hacer un bot de WASAP con varias sesiones(diferentes numeros) pero al 2 numero, le responde lo que el 1 numero tiene q ver, porfavor alguien sabe como lo puedo solucionar para diferentes numeros? |
Hi there
Thanks for the beautiful work!
I'm working on a prototype that will need to have multiple sessions (different numbers) connected at the same time to whatsapp servers.
What I'm trying to do is:
The problem is that it looks like Yowsup was not built to be used with multiple sessions, and when the second session is started, the solution stops working.
Could you please offer me some guidance in how to perform such a thing?
Thanks
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: