MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.25k stars 21.42k forks source link

error with nohup #98642

Closed anandadake closed 2 years ago

anandadake commented 2 years ago

The Example shown above is not work in background with nohup command...


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

RamanathanChinnappan-MSFT commented 2 years ago

@anandadake

Thanks for your feedback! We will investigate and update as appropriate.

SatishBoddu-MSFT commented 2 years ago

Hello @anandadake Could you please point us to the section where we see the nohup command. //?

anandadake commented 2 years ago

Hello @SatishBoddu-MSFT

I'm referring bellowed article https://learn.microsoft.com/en-us/azure/iot-develop/quickstart-send-telemetry-central?pivots=programming-language-python

and after all prerequisite i trying this nohup ./venv/bin/python ./temp_controller_with_thermostats.py but fails and gives error related to asyncio...

Note : without nohup script works fine .

anandadake commented 2 years ago

Additionally i'm using Python 3.8.0

timlt commented 2 years ago

@anandake, thanks for running the quickstart! The sample script is tested with Python and runs on the versions and OS's listed at start of article. It is not tested or supported for running with the 'nohup' command which tries to run the process in the background.

anandadake commented 2 years ago

Is that mean that the script is not capable to run in background? If not, then how the actual device sends the telemetry ?

timlt commented 2 years ago

@ryanwinter for comment on script sending telemetry.

ryanwinter commented 2 years ago

This is likely cause by the environment variables required by the script not being available in the nohup subprocess.

Can you provide:

  1. The stack trace of the error you are seeing so I can look at the exact line
  2. The output for export
ryanwinter commented 2 years ago

I replicated the error with the following output:

The problem is that the sample waits for input from the user, however stdin isn't available with nohup.

Device was assigned
iotc-79c9aa46-aade-403d-8722-829500ee91b5.azure-devices.net
python
Updating pnp properties for root interface
{'serialNumber': 'some_serial_number'}
Updating pnp properties for thermostat1
{'thermostat1': {'maxTempSinceLastReboot': 98.34, '__t': 'c'}}
Updating pnp properties for thermostat2
{'thermostat2': {'maxTempSinceLastReboot': 48.92, '__t': 'c'}}
Updating pnp properties for deviceInformation
{'deviceInformation': {'swVersion': '5.5', 'manufacturer': 'Contoso Device Corporation', 'model': 'Contoso 4762B-turbo', 'osName': 'Mac Os', 'processorArchitecture': 'x86-64', 'processorManufacturer': 'Intel', 'totalStorage': 1024, 'totalMemory': 32, '__t': 'c'}}
Listening for command requests and property updates
Press Q to quit
Sending telemetry from various components
Traceback (most recent call last):
  File "temp_controller_with_thermostats.py", line 419, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "temp_controller_with_thermostats.py", line 398, in main
    await user_finished
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "temp_controller_with_thermostats.py", line 237, in stdin_listener
    selection = input("Press Q to quit\n")
OSError: [Errno 9] Bad file descriptor
ERROR:asyncio:_GatheringFuture exception was never retrieved
future: <_GatheringFuture finished exception=CancelledError()>
asyncio.exceptions.CancelledError
ERROR:asyncio:_GatheringFuture exception was never retrieved
future: <_GatheringFuture finished exception=CancelledError()>
asyncio.exceptions.CancelledError
timlt commented 2 years ago

Thanks @ryanwinter

@anandadake thanks again for running the quickstart sample and raising the question. You have the info to run the script at this point, just run as indicated in the doc (copy and paste the code, without using 'nohup' command). Thank you!

please-close

anandadake commented 2 years ago

Then how could i run in background process ? My intention is to run the script on VM and it should keep running even after i close the shell or logout from VM

ryanwinter commented 2 years ago

Hi @anandadake,

This is a sample is was not written to be run as a background task, hence the reliance on user input during execution. This is not a supported scenario for any of our samples and guides.

You could modify the script to remove the STDIN reliance as a first step to what you are looking for.

Ryan