I am new to asynchronous message queues and would be using the python api to kestrel, pykestrel in my project (https://github.com/empower/pykestrel).
The example on the github page,has the following line:
q.add("test job")
What is test job in practice ?. Can someone please provide some more examples demonstrating the use of pykestrel ?
Please Help
Thank You
The code in your question adds a message to the Kestrel Queue.
kestrel.next()
will get the next message in the queue.
You can find full documentation in the code : https://github.com/empower/pykestrel/blob/master/kestrel/client.py
Also, kestrel uses the memcache protocol which you can find here : http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt
Basically, anything that works with Memcache can be used with Kestrel.
For posterity, note that the original project is at https://github.com/matterkkila/pykestrel/ and is newer.
"test job", in practice, is the description of the action to be done by your worker. For example, if you're a video site, once you receive a new video:
"MakeIcon('/path/to/video')"
Your worker process should know what to do based on that message. The message can be larger and contain more information.
It can be anything, encoded anyway you please.
Related
When using the sample code in the wiki of python-kucoin:
https://python-kucoin.readthedocs.io/en/latest/websockets.html
I keep on getting "sleeping to keep loop open" while in debug mode (I am using PyCharm).
Digging into the code, I also realized that at this stage of the code (res['instanceServers'][0]['endpoint']):
https://github.com/sammchardy/python-kucoin/blob/develop/kucoin/client.py#L183
the enpoint is
wss://ws-api.kucoin.com/endpoint
while according from Kucoin documentation it should be:
wss://push1-v2.kucoin.com/endpoint
Is this expected?
I forced the code to change this but it doesn't help receiving any data either...
How long am I supposed to wait before receiving any data from the websocket?
Most of SammChardy's Kucoin Python package hasn't been updated in years. The other one at:
https://github.com/Kucoin/kucoin-python-sdk
Looks very much similar to SammChardy's but is updated more regularly. I tried both and settled on the latter one. Give it a go and see if it'll resolve your issues.
I have a script running on my raspberry, these script is started from a command from an php page. I’ve multiple if stetements, now I would like to pass new arguments to the script whithout stopping it. I found lots of information by passing arguments to the python script, but not if its possible while the svpcript is already running to pass new arguments. Thanks in advance!
The best option for me is to use a configuration file input for your script.
Some simple yaml will do. Then in a separate thread you must observe the hash of the file, if it gets changed that
means somebody has updated your file and you must re/adjust your inputs.
Basically you have that constant observer running all the time.
You need some sort of IPC mechanism really. As you are executing/updating the script from a PHP application, I'd suggest you'll look into something like ZeroMQ which supports both Python and PHP, and will allow you to do a quick and dirty Pub/Sub implementation.
The basic idea is, treat your python script as a subscriber to messages coming from the PHP application which publishes them as and when needed. To achieve this, you'll want to start your python "script" once and leave it running in the background, listening for messages on ZeroMQ. Something like this should get you going
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")
while True:
# Wait for next message from from your PHP application
message = socket.recv()
print("Recieved a message: %s" % message)
# Here you should do the work you need to do in your script
# Once you are done, tell the PHP application you are done
socket.send(b"Done and dusted")
Then, in your PHP application, you can use something like the following to send a message to your Python service
$context = new ZMQContext();
// Socket to talk to server
$requester = new ZMQSocket($context, ZMQ::SOCKET_REQ);
$requester->connect("tcp://localhost:5555");
$requester->send("ALL THE PARAMS TO SEND YOU YOUR PYTHON SCRIPT");
$reply = $requester->recv();
Note, I found the above examples using a quick google search (and amended slightly for educational purposes), but they aren't tested, and purely meant to get you started. For more information, visit ZeroMQ and php-zmq
Have fun.
I would like to only receive messages within a time frame, as the messages before and after have corrupted data.
I know that I can seek to the starting position, so that issue is solved, how do I configure the other end (stop at a specific time).
Any answers or suggestions are highly appreciated.
After setting the interval I plan to read the messages from python code if it helps.
There is no integrated solution for that. You have to implement a filter in Python for discarding messages with corrupted data.
However, your use case is interesting and opening a feature request on the issue tracker could help you (and others) in the future.
I would like to know where does the function pythoncom.PumpMessage() stores the message when it comes into play. I was going through a site and just saw a Python Script for Key logger, I copied the code and used it on my computer but I don't feel safe, after deleting that code I think it's still running in the background and copying my keypresses. Is it so, please help.
If the python script was sending messages to anyone, you'd probably be able to tell by looking at the code. Somewhere there would be a block of code sending some file to a server.
As for PumpMessages(), it
Pumps all messages for the current thread until a WM_QUIT message.
According to this documentation. You can find other answered questions on this with a Google search as well. Pythoncom isn't sending any information to an external source in and of itself, however your script might be. You'd have to check your code for a block doing that.
As for it running after you delete the script, highly unlikely. If you didn't manually or programmatically (in the script) attach the Python script to some daemon, it isn't manifesting itself anywhere. You may be over-estimating the power of a basic Python keylogger. I wouldn't worry.
I've tried keyloggers before with pythoncom, and I've never had a problem. You can also look in the pythoncom library to find the PumpMessages() function and see if that is sending anything.
ok I am well aware there are many other questions about this, but I have been searching and have yet to find a solid proper answer that doesnt revolve around jabber or something worse. (no offense to jabber users, just I don't want all the extras that come with it)
I currently have msnp and twisted.words, I simply want to send and receive messages, have read many examples that have failed to work, and msnp is poorly documented.
My preference is msnp as it requires much less code, I'm not looking for something complicated.
Using this code I can login, and view my friends that are online (can't send them messages though.):
import msnp
import time, threading
msn = msnp.Session()
msn.login('XXXXXXX#hotmail.com', 'XXXXXX')
msn.sync_friend_list()
class MSN_Thread(threading.Thread):
def run(self):
msn.start_chat("XXXXXXX#hotmail.com") #this does not work
while True:
msn.process()
time.sleep(1)
start_msn = MSN_Thread()
start_msn.start()
I hope I have been clear enough, its pretty late and my head is not in a clear state after all this msn frustration.
edit: since it seems msnp is extremely outdated could anyone recommend with simple examples on how I could achieve this?
Don't need anything fancy that requires other accounts.
There is also xmpp which is used for gmail.
You are using a library abandoned in 2004 so i'm not sure if msnp could still be used to talk on MSN.
Anyway i would try with:
while True:
msn.process(chats = True)
time.sleep(1)
using the contact id and not the email address.
contacts = msn.friend_list.get_friends()
contact_id = contacts.get_passport_id()
Your code just start the chat without sending anything; you need to add the code to send message.
Have a look to send_message method in this tutorial.
It looks like papyon is a maintained fork of the pymsn library, and is currently used by telepathy-butterfly and amsn2.
papyon is an MSN client library, that tries to abstract the MSN protocol gory details. It is a fork of the unmaintained pymsn MSN library. papyon uses the GLib main event loop to process the network events in an asynchronous manner.