×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    4

    My script is randomly dieing

    Hi, I have just recently started programming with Python and as part of a learning project I decided to make a WiFi remote control for my PC (also I don't have bluetooth in my PC so the hundred other projects out there don't work for me) and I have run into a problem. Everytime I run the script it works fine for about 2-3 minutes then it will just close down the shell and return to the menu without showing any errors. I have been running it in the script shell and PED, I haven't tried creating a sis file but I doubt that will work any better.

    I have tried searching for the problem and haven't found anything but it is an extremely hard thing to search for because I'm not getting any error messages. So can someone please help me out here.

    I have put my scripts on pastebin, there are 3 scripts that need to be used:
    netServer.py is the server which runs on the PC.
    remoteCmds.py is a module for the server so when running the netServer.py script make sure you are in the same directory as this file.
    WiFiRemote.py is the client for the phone.

  2. #2
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: My script is randomly dieing

    Hi Mike

    Nice feature under construction, no ? Great. My 2 cents (maybe one cent):

    1) Is __reconnect__() working ? Since you have already called bind, further call to bind to same port will failure. Just call accept(), do not call bind again.

    2) socket.makefile() may give you a better way to handle command lines. Just create the makefile from your socket (file_like_interface = your_socket.makefile()) and use readline() instead receiving each byte.

    http://croozeus.com/blogs/?p=1259

    3) use sendall() instead send() to ensure that all data are sent at each call

    4) Queue objects may be useful for passing commands and avoid critical sections. It deserves a look.

    5) If the program is closing and try/catch does not help, try to log to file:

    http://croozeus.com/blogs/?p=983

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    4

    Re: My script is randomly dieing

    Quote Originally Posted by marcelobarrosalmeida View Post
    1) Is __reconnect__() working ? Since you have already called bind, further call to bind to same port will failure. Just call accept(), do not call bind again.
    That is working at the moment, but it would be better without binding again so I'll try that. The only reason I put it there in the first place is because I suspect that the socket was dieing and that was cause the client to have a problem and just die, but the reconnect didn't fix it so I assume that wasn't the problem.

    Quote Originally Posted by marcelobarrosalmeida View Post
    2) socket.makefile() may give you a better way to handle command lines. Just create the makefile from your socket (file_like_interface = your_socket.makefile()) and use readline() instead receiving each byte.

    http://croozeus.com/blogs/?p=1259
    That would be heaps better, my way is extremely ugly.

    Quote Originally Posted by marcelobarrosalmeida View Post
    3) use sendall() instead send() to ensure that all data are sent at each call
    What is the difference?

    Quote Originally Posted by marcelobarrosalmeida View Post
    4) Queue objects may be useful for passing commands and avoid critical sections. It deserves a look.
    Ok, I'll take a look at that.

    Quote Originally Posted by marcelobarrosalmeida View Post
    5) If the program is closing and try/catch does not help, try to log to file:

    http://croozeus.com/blogs/?p=983
    Yes, that will be useful the try/catch method doesn't work because it quits the shell before I get to read it.


    Thanks for the help.


    edit: I forgot to mention this in my first post, I know that the problem is on the client because the server is having a "connection rest by peer" error because the client is closing the socket.

  4. #4
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: My script is randomly dieing

    Hi

    When you use send(buffer) the amount of sent bytes may be less or equal len(buffer). send() may not send all buffer and you need to check its return always (the amount of sent bytes). It may vary depending on network or network stack conditions. By its turn, sendall(buffer) only returns when all buffer is sent(). So, even though sendall() did not come from standard socket library (you do not have it in C), it is really helpful.

    Marcelo

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    4

    Re: My script is randomly dieing

    I found my problem, it was in the loop() function. I had made it loop by making the loop function call itself when it had finished everything so eventually there were hundreds of the loop function running inside each other so the phone ran out of memory and died.

    Thanks for all your help.

  6. #6
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: My script is randomly dieing

    Quote Originally Posted by madm1k3 View Post
    I found my problem, it was in the loop() function. I had made it loop by making the loop function call itself when it had finished everything so eventually there were hundreds of the loop function running inside each other so the phone ran out of memory and died.
    You should have seen "RuntimeError: maximum recursion depth exceeded" error note. Better check / reconsider your debug logging system.

    Cheers,

    --jouni

  7. #7
    Registered User
    Join Date
    Dec 2009
    Posts
    4

    Re: My script is randomly dieing

    Strange that I didn't get that error then. I was never able to find any errors, even when I was logging to a file, but I was able to find out whereabouts in the script the problem was occurring and changing how the loop is done so that it isn't recursive fixed the problem.

    If it makes a difference I am using version '1.4.5' rather than '1.9.7' because I was having a lot of trouble getting '1.9.7' installed on my phone.

Similar Threads

  1. Quickest way to run script from home screen
    By jtullis in forum Symbian
    Replies: 10
    Last Post: 2009-08-25, 14:06
  2. json script tag hack does not work from window.onload
    By hp3 in forum Browsing and Mark-ups
    Replies: 2
    Last Post: 2008-09-24, 15:26
  3. script working,but standalone doesn't
    By bugb in forum Symbian
    Replies: 2
    Last Post: 2007-03-12, 14:14
  4. Install a script as a standalone app !
    By cyke64 in forum Symbian
    Replies: 5
    Last Post: 2006-07-18, 02:24
  5. write perl/python script in your S60 phone
    By kamijawa in forum Symbian
    Replies: 5
    Last Post: 2006-06-03, 15:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×