English 中文(简体)
带屏幕的制药远程部署影响序列接口
原标题:PyCharm remote deployment with screen affects serial interface
I have a flask app.py that I m developing on my local machine. The flask app uses a serial interface (pyserial) that is connected to a remote machine. I setup PyCharm for remote deployment on the remote machine. When I deploy and run the app remotely (from my local machine) I want to launch it inside a detached screen so that I can disconnect from SSH if needed. To do this, I wrote this simple python script detach_app.py: import sys import subprocess import shlex command = "/opt/homebrew/bin/screen -S flask -d -m " + sys.executable + " app.py" command = shlex.split(command) subprocess.Popen(command, start_new_session=True) When in PyCharm I remote deploy detach_app.py it runs app.py in a screen and detaches the screen. It also assigns the screen to a new session so that it becomes the child of the init process and doesn t get shut down when the python script ends. This works well because if I need to check on the process later on I just SSH into the machine through a terminal in PyCharm and do screen -r flask. However, I m experiencing a weird issue where the serial interface is misbehaving when I launch app.py through this method. In particular a device would be able to open the serial port but it would only send empty strings. Note that this behavior doesn t happen if: I remotely deploy app.py I locally launch app.py by itself or through screen I remotely deploy detach_app.py but instead of using screen I use nohup It seems the serial interface issue is caused by a combination of screen and PyCharm remote deployment. I m aware that this is a far fetched question but I m really struggling to understand what would be the next thing to try to investigate the problem. Does anybody have any pointer for this?
问题回答
After some more in depth debugging I discovered that the issue was only related to pyserial and MacOS and had nothing to do with screen. In particular I noticed that the issue of reading a blank usb reply was happening exactly after 1 minute of exiting a VNC connection. I then suspected that the OS was going in sleep and deactivating tty for some reason, even if I had set it up to never go to sleep. I launched the command pmset -g and noticed these two lines sleep 1 (sleep prevented by screensharingd, powerd) ttyskeepawake 1 man pmset has more details on how ttyskeepawake and sleep interact but if you notice, screensharingd (VNC) prevents the OS from going to sleep. When VNC is exited, it takes one minute for it to go to sleep. I modified the settings using the command sudo pmset -a sleep 0 and my current full status is: System-wide power settings: Currently in use: standby 0 Sleep On Power Button 1 autorestart 0 SleepServices 0 powernap 0 networkoversleep 0 disksleep 0 sleep 0 (sleep prevented by screensharingd, powerd) ttyskeepawake 1 displaysleep 0 tcpkeepalive 1 lowpowermode 0 womp 1




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签