Open carlosfelipe29 opened 8 years ago
Sorry for my poor english. This code receives time (in seconds) by param. The script runs during that time. When time is over, script stop.
import signal
if __name__ == "__main__":
TIME_ = int(sys.argv[1]) #time in seconds
## handler for ALARM
def handlerTimeOut(signum, frame):
raise Exception()
CREDENTIALS = ("NUM", "KEY")
layers = (
YOURSTACK,
YowParallelLayer([YowAuthenticationProtocolLayer, YowNotificationsProtocolLayer, YowMessagesProtocolLayer,YowReceiptProtocolLayer, YowAckProtocolLayer]),
YowAxolotlLayer,
YowLoggerLayer,
YowCoderLayer,
YowCryptLayer,
YowStanzaRegulator,
YowNetworkLayer
)
stack = YowStack(layers)
stack.setProp(YowAuthenticationProtocolLayer.PROP_PASSIVE, True)
stack.setCredentials(CREDENTIALS)
stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])
stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
stack.setProp(YowCoderLayer.PROP_RESOURCE, env.CURRENT_ENV.getResource())
stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
## set alarm
signal.signal(signal.SIGALRM, handlerTimeOut)
signal.alarm(TIME_)
try:
stack.loop()
except Exception, exc:
print "Time over"
Hi, it really helps me.
It means, if I put a integer(num) on TIME_ = int( NUM), the stack.loop() will be open over a certain time, enough to read a messages on the server and then the connection is close. But it is possible to connect again. (like a switching).
thanks again
@bicapa Thanks a lot, It really works, It opens the stack.loop() some seconds (that I define). I tried to put on a thread, but it is not possible.
I can not use SIGNAL module inside a Thread, it only works on a main thread.
Any ideas to stop the thread of read messages (maybe threadind.TIMER( ...) )
thanks.
hi carlosfelipe29, did you find any solution. I am in same problem and trying to find any solution. What I am doing I have multiple channels and I am switching that without exiting the program. So I creating the thread for each channel and when the task done I close that thread and create another thread with another channel. But I couldn't found any way to exit the stack.loop without sending ctrl+c but ctrl+c exit the complete program.
Thanks
hi @tgalal , @aesedepece, @pungoyal .
Is there any way to stop or kill the stack.start() procedure when I received a request, without exit the program?? It means, to stop or to disconnect meanwhile I do another process and after that, it connects and Answer.
def start(self): self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)) try: self.stack.loop() except AuthError as e: print("Authentication Error: %s" % e.message)
I run the script on a threading process to have simultaneously different task. stack=YowsupReceiveStack(credential()) stack.start() But, After I receive the first request (word by whatsapp) it is able to get a response, after that it freezes, and the next requests does not seem to be read (message were lost), only when I do Ctrl+C and run again, it appears.
I try to use event_disconnect without succeded.
is there any way to stop this stack.start() , maybe call after, a function stack.stop() to do nothing and get disconnected for that iteration do what I want,and get alive when it runs the stack.start() again ?.
I appreciate your technical support .
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.