python script fails running as a daemon (EOFError: EOF when reading a line) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!break/interrupt a time.sleep() in pythonHow do I check what version of Python is running my script?Why do people write the #!/usr/bin/env python shebang on the first line of a Python script?How to make a Python script standalone executable to run without ANY dependency?How to read a large file, line by line, in PythonWhy is reading lines from stdin much slower in C++ than Python?EOFError: EOF when reading a lineinput has an EOF error only when I run in command lineEOFError: EOF when reading a line in a calculator scriptpython 3 EOFError: EOF when reading a lineStop script, EOFError: EOF when reading a line

BITCOIN: on a chart what does it mean for the USD price to be higher then marketcap?

Understanding p-Values using an example

How to change the tick of the color bar legend to black

How does the math work when buying airline miles?

The Nth Gryphon Number

Can two person see the same photon?

Does the Mueller report show a conspiracy between Russia and the Trump Campaign?

retrieve food groups from food item list

How would you say "es muy psicólogo"?

Asymptotics question

Why is a lens darker than other ones when applying the same settings?

How many time has Arya actually used Needle?

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

Omitting the following parentheses

What is the difference between CTSS and ITS?

Is there public access to the Meteor Crater in Arizona?

Should a wizard buy fine inks every time he want to copy spells into his spellbook?

Does the Black Tentacles spell do damage twice at the start of turn to an already restrained creature?

Short story about a child who is a miniature, living Earth

What adaptations would allow standard fantasy dwarves to survive in the desert?

Is there more forest in the Northern Hemisphere now than 100 years ago?

Positioning dot before text in math mode

Why not send Voyager 3 and 4 following up the paths taken by Voyager 1 and 2 to re-transmit signals of later as they fly away from Earth?

Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?



python script fails running as a daemon (EOFError: EOF when reading a line)



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!break/interrupt a time.sleep() in pythonHow do I check what version of Python is running my script?Why do people write the #!/usr/bin/env python shebang on the first line of a Python script?How to make a Python script standalone executable to run without ANY dependency?How to read a large file, line by line, in PythonWhy is reading lines from stdin much slower in C++ than Python?EOFError: EOF when reading a lineinput has an EOF error only when I run in command lineEOFError: EOF when reading a line in a calculator scriptpython 3 EOFError: EOF when reading a lineStop script, EOFError: EOF when reading a line



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I've created a python3 script that runs fine on command line but when I try to run as a daemon in MacosX gives error 'EOFError: EOF when reading a line'. Basically code is as follows:



 (...)

def main():

# Connect
port, speed = connect_port()

device = XBeeDevice(port, speed)

try:
device.open()
# print("Waiting for data...n")

(...)

device.add_packet_received_callback(packet_received_callback)
input()

finally:
if device is not None and device.is_open():
device.close()

if __name__ == '__main__':
main()


plist seems to be fine as script starts and runs once before to give error:



Traceback (most recent call last):
File "/maslestorres.cat/jardiNet_datalogger.py", line 214, in <module>
main()
File "/maslestorres.cat/jardiNet_datalogger.py", line 206, in main
input()
EOFError: EOF when reading a line


So basically I don't know how to adapt the input() line to allow to run as a daemon. Python is version 3.7.2 and MacOSX is 10.8.5.










share|improve this question






















  • Please explain what you’re doing in more detail. What is the purpose of input() in your code? Does it wait for the user’s approval to resume operation? Typically the whole point of a daemon is to run continuously without user interaction.

    – Vasiliy Faronov
    Mar 22 at 14:03











  • input() function is just to ensure main never ends and callbacks are executed. Similar behavior can be obtained with a busy wait loop --> while True: pass but obviously this loop wastes CPU

    – joanba
    Mar 22 at 14:30












  • Do I understand correctly that you want your daemon to device.open() once and then wait for packets indefinitely, running packet_received_callback on each one?

    – Vasiliy Faronov
    Mar 22 at 14:37

















0















I've created a python3 script that runs fine on command line but when I try to run as a daemon in MacosX gives error 'EOFError: EOF when reading a line'. Basically code is as follows:



 (...)

def main():

# Connect
port, speed = connect_port()

device = XBeeDevice(port, speed)

try:
device.open()
# print("Waiting for data...n")

(...)

device.add_packet_received_callback(packet_received_callback)
input()

finally:
if device is not None and device.is_open():
device.close()

if __name__ == '__main__':
main()


plist seems to be fine as script starts and runs once before to give error:



Traceback (most recent call last):
File "/maslestorres.cat/jardiNet_datalogger.py", line 214, in <module>
main()
File "/maslestorres.cat/jardiNet_datalogger.py", line 206, in main
input()
EOFError: EOF when reading a line


So basically I don't know how to adapt the input() line to allow to run as a daemon. Python is version 3.7.2 and MacOSX is 10.8.5.










share|improve this question






















  • Please explain what you’re doing in more detail. What is the purpose of input() in your code? Does it wait for the user’s approval to resume operation? Typically the whole point of a daemon is to run continuously without user interaction.

    – Vasiliy Faronov
    Mar 22 at 14:03











  • input() function is just to ensure main never ends and callbacks are executed. Similar behavior can be obtained with a busy wait loop --> while True: pass but obviously this loop wastes CPU

    – joanba
    Mar 22 at 14:30












  • Do I understand correctly that you want your daemon to device.open() once and then wait for packets indefinitely, running packet_received_callback on each one?

    – Vasiliy Faronov
    Mar 22 at 14:37













0












0








0








I've created a python3 script that runs fine on command line but when I try to run as a daemon in MacosX gives error 'EOFError: EOF when reading a line'. Basically code is as follows:



 (...)

def main():

# Connect
port, speed = connect_port()

device = XBeeDevice(port, speed)

try:
device.open()
# print("Waiting for data...n")

(...)

device.add_packet_received_callback(packet_received_callback)
input()

finally:
if device is not None and device.is_open():
device.close()

if __name__ == '__main__':
main()


plist seems to be fine as script starts and runs once before to give error:



Traceback (most recent call last):
File "/maslestorres.cat/jardiNet_datalogger.py", line 214, in <module>
main()
File "/maslestorres.cat/jardiNet_datalogger.py", line 206, in main
input()
EOFError: EOF when reading a line


So basically I don't know how to adapt the input() line to allow to run as a daemon. Python is version 3.7.2 and MacOSX is 10.8.5.










share|improve this question














I've created a python3 script that runs fine on command line but when I try to run as a daemon in MacosX gives error 'EOFError: EOF when reading a line'. Basically code is as follows:



 (...)

def main():

# Connect
port, speed = connect_port()

device = XBeeDevice(port, speed)

try:
device.open()
# print("Waiting for data...n")

(...)

device.add_packet_received_callback(packet_received_callback)
input()

finally:
if device is not None and device.is_open():
device.close()

if __name__ == '__main__':
main()


plist seems to be fine as script starts and runs once before to give error:



Traceback (most recent call last):
File "/maslestorres.cat/jardiNet_datalogger.py", line 214, in <module>
main()
File "/maslestorres.cat/jardiNet_datalogger.py", line 206, in main
input()
EOFError: EOF when reading a line


So basically I don't know how to adapt the input() line to allow to run as a daemon. Python is version 3.7.2 and MacOSX is 10.8.5.







python python-3.x macos launchd






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 11:46









joanbajoanba

149112




149112












  • Please explain what you’re doing in more detail. What is the purpose of input() in your code? Does it wait for the user’s approval to resume operation? Typically the whole point of a daemon is to run continuously without user interaction.

    – Vasiliy Faronov
    Mar 22 at 14:03











  • input() function is just to ensure main never ends and callbacks are executed. Similar behavior can be obtained with a busy wait loop --> while True: pass but obviously this loop wastes CPU

    – joanba
    Mar 22 at 14:30












  • Do I understand correctly that you want your daemon to device.open() once and then wait for packets indefinitely, running packet_received_callback on each one?

    – Vasiliy Faronov
    Mar 22 at 14:37

















  • Please explain what you’re doing in more detail. What is the purpose of input() in your code? Does it wait for the user’s approval to resume operation? Typically the whole point of a daemon is to run continuously without user interaction.

    – Vasiliy Faronov
    Mar 22 at 14:03











  • input() function is just to ensure main never ends and callbacks are executed. Similar behavior can be obtained with a busy wait loop --> while True: pass but obviously this loop wastes CPU

    – joanba
    Mar 22 at 14:30












  • Do I understand correctly that you want your daemon to device.open() once and then wait for packets indefinitely, running packet_received_callback on each one?

    – Vasiliy Faronov
    Mar 22 at 14:37
















Please explain what you’re doing in more detail. What is the purpose of input() in your code? Does it wait for the user’s approval to resume operation? Typically the whole point of a daemon is to run continuously without user interaction.

– Vasiliy Faronov
Mar 22 at 14:03





Please explain what you’re doing in more detail. What is the purpose of input() in your code? Does it wait for the user’s approval to resume operation? Typically the whole point of a daemon is to run continuously without user interaction.

– Vasiliy Faronov
Mar 22 at 14:03













input() function is just to ensure main never ends and callbacks are executed. Similar behavior can be obtained with a busy wait loop --> while True: pass but obviously this loop wastes CPU

– joanba
Mar 22 at 14:30






input() function is just to ensure main never ends and callbacks are executed. Similar behavior can be obtained with a busy wait loop --> while True: pass but obviously this loop wastes CPU

– joanba
Mar 22 at 14:30














Do I understand correctly that you want your daemon to device.open() once and then wait for packets indefinitely, running packet_received_callback on each one?

– Vasiliy Faronov
Mar 22 at 14:37





Do I understand correctly that you want your daemon to device.open() once and then wait for packets indefinitely, running packet_received_callback on each one?

– Vasiliy Faronov
Mar 22 at 14:37












1 Answer
1






active

oldest

votes


















0














By its very nature, a daemon cannot input() from the console. You need another way to suspend the main thread indefinitely while letting the XBee PacketListener thread to keep running callbacks.



The easiest way to accomplish this would be to replace input() with:



while True:
time.sleep(1000000) # arbitrarily large number


When it’s time to shut down, your system’s service manager will stop your daemon:



  • either by sending SIGTERM — in which case your daemon will terminate immediately, without executing the finally block;

  • or by sending SIGINT — in which case a KeyboardInterrupt exception will bubble out of time.sleep(1000000), and the finally block will run.

In either case, your process should stop quickly.



For a more correct solution, capable also of handling SIGTERM gracefully, see here: https://stackoverflow.com/a/46346184/200445






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298911%2fpython-script-fails-running-as-a-daemon-eoferror-eof-when-reading-a-line%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    By its very nature, a daemon cannot input() from the console. You need another way to suspend the main thread indefinitely while letting the XBee PacketListener thread to keep running callbacks.



    The easiest way to accomplish this would be to replace input() with:



    while True:
    time.sleep(1000000) # arbitrarily large number


    When it’s time to shut down, your system’s service manager will stop your daemon:



    • either by sending SIGTERM — in which case your daemon will terminate immediately, without executing the finally block;

    • or by sending SIGINT — in which case a KeyboardInterrupt exception will bubble out of time.sleep(1000000), and the finally block will run.

    In either case, your process should stop quickly.



    For a more correct solution, capable also of handling SIGTERM gracefully, see here: https://stackoverflow.com/a/46346184/200445






    share|improve this answer





























      0














      By its very nature, a daemon cannot input() from the console. You need another way to suspend the main thread indefinitely while letting the XBee PacketListener thread to keep running callbacks.



      The easiest way to accomplish this would be to replace input() with:



      while True:
      time.sleep(1000000) # arbitrarily large number


      When it’s time to shut down, your system’s service manager will stop your daemon:



      • either by sending SIGTERM — in which case your daemon will terminate immediately, without executing the finally block;

      • or by sending SIGINT — in which case a KeyboardInterrupt exception will bubble out of time.sleep(1000000), and the finally block will run.

      In either case, your process should stop quickly.



      For a more correct solution, capable also of handling SIGTERM gracefully, see here: https://stackoverflow.com/a/46346184/200445






      share|improve this answer



























        0












        0








        0







        By its very nature, a daemon cannot input() from the console. You need another way to suspend the main thread indefinitely while letting the XBee PacketListener thread to keep running callbacks.



        The easiest way to accomplish this would be to replace input() with:



        while True:
        time.sleep(1000000) # arbitrarily large number


        When it’s time to shut down, your system’s service manager will stop your daemon:



        • either by sending SIGTERM — in which case your daemon will terminate immediately, without executing the finally block;

        • or by sending SIGINT — in which case a KeyboardInterrupt exception will bubble out of time.sleep(1000000), and the finally block will run.

        In either case, your process should stop quickly.



        For a more correct solution, capable also of handling SIGTERM gracefully, see here: https://stackoverflow.com/a/46346184/200445






        share|improve this answer















        By its very nature, a daemon cannot input() from the console. You need another way to suspend the main thread indefinitely while letting the XBee PacketListener thread to keep running callbacks.



        The easiest way to accomplish this would be to replace input() with:



        while True:
        time.sleep(1000000) # arbitrarily large number


        When it’s time to shut down, your system’s service manager will stop your daemon:



        • either by sending SIGTERM — in which case your daemon will terminate immediately, without executing the finally block;

        • or by sending SIGINT — in which case a KeyboardInterrupt exception will bubble out of time.sleep(1000000), and the finally block will run.

        In either case, your process should stop quickly.



        For a more correct solution, capable also of handling SIGTERM gracefully, see here: https://stackoverflow.com/a/46346184/200445







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 22 at 15:18

























        answered Mar 22 at 15:12









        Vasiliy FaronovVasiliy Faronov

        8,89512735




        8,89512735





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298911%2fpython-script-fails-running-as-a-daemon-eoferror-eof-when-reading-a-line%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해