Socket code not executing properly in a thread (Windows)

T

Thomas Jollans

On 07/08/2012 12:55 PM, Andrew D'Angelo wrote:

Please set your clock to the correct date and time.
(If it would help, the
full code can be seen here: http://lickitung.it.cx/exe/bot/bot.py):

No, it can't.
def sendPrivateMessage(channel, message):#private message send function

global mute

if mute == 0:

IRC.send("PRIVMSG " + channel + " :" + message + "\r\n") #IRC being
the socket

Do you have an error message or something?

Without knowing more about the IRC library you're using, it's hard to
say what the reason behind the platform-dependent behaviour is. However,
it's clear that you should be calling IRC.send from the main thread.
That shouldn't be too hard to achieve, save the message to some sort of
event or outgoing message queue that the main thread processes in sequence.

(This sounds to me like an application better implemented thread-less,
using select() or some method of asynchronous I/O. Just a shame that
Python makes neither at all pleasant and leaves threads as the nicest
option)

Thomas
 
A

Andrew D'Angelo

Thomas Jollans said:
On 07/08/2012 12:55 PM, Andrew D'Angelo wrote:

Please set your clock to the correct date and time.

My BIOS battery has died and I haven't gotten a chance to replace it. Made a
mistake when setting the date on boot-up. :-\
Do you have an error message or something?

No, it simply does not send the message.
Without knowing more about the IRC library you're using

I am sending plain text to the socket, without a library.
However,
it's clear that you should be calling IRC.send from the main thread.
That shouldn't be too hard to achieve, save the message to some sort of
event or outgoing message queue that the main thread processes in
sequence.

Good idea, thanks.
 
J

John Nagle

Hi, I've been writing an IRC chatbot that an relay messages it receives as
an SMS.

We have no idea what IRC module you're using.
As it stands, I can retrieve and parse SMSs from Google Voice perfectly

The Google Voice code you have probably won't work once you have
enough messages stored that Google Voice returns them on multiple
pages. You have to read all the pages. If there's any significant
amount of traffic, the completed messages have to be moved or deleted,
or each polling cycle returns more data than the last one.

Google Voice isn't a very good SMS gateway. I used to use it,
but switched to Twilio (which costs, but works) two years ago.

John Nagle
 
A

Andrew D'Angelo

We have no idea what IRC module you're using.

I am sending plain text to the socket, sorry for not mentioning it before.
At the simplest level, it appears that when the code runs in Windows, data
is not sent to a socket when inside a thread, while on OS X it is.
Also, running the sned to socket code inside the main loop would not work,
as the main loop pauses until it recieves data from the socket (an IRC
message), which is why I didn't put the SMS code in the main loop in the
first place.
The Google Voice code you have probably won't work once you have
enough messages stored that Google Voice returns them on multiple
pages.

I know that this is not the problem because the code works fine on OS X, but
not Windows, where I actually need it to run. In addition, each message is
deleted as it is parsed and no other SMSs are sent to the number, so fill-up
should not be a problem.
 
A

Andrew D'Angelo

Hi, I've been writing an IRC chatbot that an relay messages it recieves as
an SMS.
As it stands, I can retrieve and parse SMSs from Google Voice perfectly, and
print them to the console. The problem lies in actually posting the message
to the IRC channel. Since the SMS checker runs in a thread apart from the
regular chatbot duties, the socket communication also takes place in the
thread. Something even stranger is that the code works on OS X, but not on
WIndows, where my server runs. Here is a code snippet (If it would help, the
full code can be seen here: http://lickitung.it.cx/exe/bot/bot.py):
def checkVoice():

global upHz

global CHANNEL

global mute

while 1:

print "Update voice!"

voice.sms()

msgitems = [] #Extract all conversations by searching for a DIV with
an ID at top level.

tree = BeautifulSoup(voice.sms.html)

conversations = tree.findAll("div",attrs={"id" :
True},recursive=False)

#parsing code cut for brevity - I know it works, though

sendPrivateMessage(CHANNEL,message) #as far as I can tell,
this is failing to execute

time.sleep(upHz)

def sendPrivateMessage(channel, message):#private message send function

global mute

if mute == 0:

IRC.send("PRIVMSG " + channel + " :" + message + "\r\n") #IRC being
the socket
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top