(OSX)launchctl不允许Python停止

时间:2012-03-31 17:39:41

标签: python macos osx-lion launchd

我在Lion(10.7.3)上使用launchctl在系统启动时在2个不同的端口上加载2个SickBeard实例(一个python脚本)。

我在〜/ Library / LaunchAgents中的plist如下所示。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.sickbeard.sickbeard</string>
  <key>ProgramArguments</key>
  <array>
       <string>/Library/Frameworks/Python.framework/Versions/2.7/bin/python</string>
       <string>/Users/james/Applications/Sick-Beard/SickBeard.py</string>
       <string>-q</string>
       <string>-d</string>
  </array>

  <key>StandardOutPath</key>
  <string>/var/log/sickbeard/sickbeard.log</string>
  <key>StandardErrorPath</key>
  <string>/var/log/sickbeard/sickbeard_error.log</string>

  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

我已经确认python从该位置启动,并且SB也是正确的......实际上两个Python实例在启动时都正确加载 - 请参阅&#34; top&#34;下方。

Processes: 94 total, 3 running, 91 sleeping, 450 threads                                                  20:22:54
Load Avg: 6.19, 6.24, 6.39  CPU usage: 94.33% user, 5.66% sys, 0.0% idle
SharedLibs: 82M resident, 0B data, 11M linkedit.
MemRegions: 10801 total, 1189M resident, 40M private, 212M shared.
PhysMem: 927M wired, 1622M active, 3207M inactive, 5757M used, 2435M free.
VM: 222G vsize, 1344M framework vsize, 110371(0) pageins, 89(0) pageouts.
Networks: packets: 1118035/1205M in, 2206764/2119M out. Disks: 323025/15G read, 52125/11G written.

PID   COMMAND      %CPU  TIME     #TH   #WQ  #POR #MRE RPRVT  RSHRD  RSIZE  VPRVT  VSIZE  PGRP PPID STATE    UID
1312  top          5.8   00:00.55 1/1   0    28   38   1044K  216K   1760K  19M    2379M  1312 733  running  0
1246  taskgated    0.0   00:00.01 1     0    30   40   496K   320K   1860K  28M    2388M  1246 1    sleeping 0
1242  mdworker     0.0   00:00.10 3     1    54   70   1540K  13M    5748K  31M    2418M  1242 280  sleeping 89
1241  mdworker     0.0   00:00.98 3     1    50   78   6952K  6252K  12M    28M    2416M  1241 217  sleeping 501
733   bash         0.0   00:00.01 1     0    21   24   288K   760K   1056K  17M    2378M  733  732  sleeping 501
732   sshd         0.0   00:00.02 1     0    13   82   256K   1444K  844K   9740K  2394M  717  717  sleeping 501
717   sshd         0.0   00:00.07 2     1    35   76   488K   1444K  2916K  8884K  2393M  717  1    sleeping 0
703   check_afp    0.0   00:00.02 4     1    44   42   480K   220K   1160K  29M    2389M  703  1    sleeping 0
516   AppleSpell   0.0   00:00.14 2     1    47   52   1172K  5544K  4680K  30M    2412M  516  217  sleeping 501
482   filecoordina 0.0   00:00.02 2     2    38   45   540K   248K   1824K  30M    2390M  482  1    sleeping 0
469   HandBrakeCLI 182.9 01:43:54 22/6  1    79   477  517M   268K   520M   707M   3092M  313  455  running  501
455   bash         0.0   00:00.02 1     0    17   23   216K   756K   888K   9648K  2378M  313  313  sleeping 501
339-  dbfseventsd  0.0   00:01.67 1     0    9    24   20K    324K   176K   20K    583M   314  338  sleeping 501
338-  dbfseventsd  0.0   00:02.03 1     0    9    24   4180K  320K   4372K  12M    591M   314  336  sleeping 0
336-  dbfseventsd  0.0   00:00.43 1     0    16   23   36K    308K   376K   5188K  583M   314  314  sleeping 0
331   Python       0.1   00:16.93 20    0    37   305  63M    2552K  60M    164M   2528M  330  1    sleeping 501
329   Python       0.2   00:20.41 20    0    47   323  55M    2552K  66M    166M   2530M  328  1    sleeping 501
314-  Dropbox      0.0   00:52.95 17    1    116  483  70M    22M    86M    99M    743M   314  217  sleeping 501
313   SABnzbd      7.1   03:41.14 23    1    113  589  170M   22M    203M   219M   2640M  313  217  sleeping 501
312   Alfred       0.0   00:00.38 2     1    110  118  6004K  31M    16M    32M    2472M  312  217  sleeping 501
311   Growl        0.0   00:00.69 5     1    149  129  8636K  21M    18M    165M   3480M  311  217  sleeping 501

我遇到的问题是,虽然&#34; launchctl start com.sickbeard.sickbeard&#34;努力开始这个过程,&#34; launchctl stop com.sickbeard.sickbeard&#34;不会阻止它。 如果我尝试从GUI启动自动更新,则会失败,提示我查看日志。 日志在适当的时间戳中包含以下内容。

Mar-24 20:15:25 DEBUG    CP Server Thread-4 :: After checking, cur_commit = a392367b16b197ca59a5017f5ecfb37ade2f26f4, newest_commit = a392367b16b197ca59a5017f5ecfb37ade2f26f4, num_commits_behind = 0
Mar-24 20:15:25 DEBUG    CP Server Thread-4 :: newest: a392367b16b197ca59a5017f5ecfb37ade2f26f4 and current: a392367b16b197ca59a5017f5ecfb37ade2f26f4 and num_commits: 0
AA
Mar-24 20:15:22 DEBUG    CP Server Thread-4 :: Git output: a392367b16b197ca59a5017f5ecfb37ade2f26f4
AA
Mar-24 20:15:22 DEBUG    CP Server Thread-4 :: git output: a392367b16b197ca59a5017f5ecfb37ade2f26f4
Mar-24 20:15:22 DEBUG    CP Server Thread-4 :: Executing "/usr/local/git/bin/git" rev-parse HEAD with your shell in /Users/james/Applications/Sick-Beard

Git确实在/ usr / local / bin / git中。 奇怪的是,我不记得改变任何可能导致这个问题的事情 - 以前有人遇到过这个问题吗? 我已经浏览了这些论坛上的所有启动线程,并尝试过对plists等所有小小的个性化更改,但没有一个真正有任何区别。

在我未经训练的眼睛看来,python正在从父SickBeard进程中妖魔化它,因此它在其管辖范围之外,然后在启动请求时停止。

非常感谢您的帮助和想法! 如果我有任何其他有用的信息,请告诉我。

:)

1 个答案:

答案 0 :(得分:1)

这不是完全守护进程,但标准Python OS X框架版本中的bin/python可执行文件实际上是一个启动程序,它执行框架中应用程序包内的真正Python可执行文件:

$ /usr/local/bin/python2.7 -c 'import sys; print(sys.executable)'
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

可能能够通过更改launchctl plist直接执行该可执行文件来获得您想要的行为。

相关问题