查看: 1863|回复: 5

Exception TypeError: "'NoneType' object is not callable" in

[复制链接]

10

主题

72

帖子

180

积分

注册会员

Rank: 2

积分
180
发表于 2018-9-27 11:50:30 | 显示全部楼层 |阅读模式
每当我在我的脚本中运行“killableprocess. popen (command)”代码时,我都会使用killableprocess包(构建在子进程之上)来运行进程,我得到以下错误:
File "killableprocess.py", line 157, in _execute_child
  winprocess.AssignProcessToJobObject(self._job, hp)
File "winprocess.py", line 37, in ErrCheckBool
  raise WinError()
WindowsError [error 5] Access is denied
Exception TypeError: "'NoneType' object is not callable" in <bound method AutoHANDLE.__del__ of <AutoHANDLE object at 0x025D42B0>> ignored
但是当我从python交互式控制台(python 2.6)运行它时,它工作得很好。这可能意味着当我从脚本中运行这个时存在权限问题,但是我不知道如何解决它们。我尝试从我作为管理员运行的cmd运行脚本,但它没有起作用。
回复

使用道具 举报

11

主题

80

帖子

199

积分

注册会员

Rank: 2

积分
199
发表于 2018-9-27 12:08:03 | 显示全部楼层
我通过切换到process目录(我试图使用inkscape)解决了一个类似的问题,它解决了我的问题
  1. import subprocess
  2. inkscape_dir=r"C:\Program Files (x86)\Inkscape"
  3. assert os.path.isdir(inkscape_dir)
  4. os.chdir(inkscape_dir)
  5. subprocess.Popen(['inkscape.exe',"-f",fname,"-e",fname_png])
复制代码
回复

使用道具 举报

3

主题

31

帖子

83

积分

注册会员

Rank: 2

积分
83
发表于 2018-9-27 15:28:31 | 显示全部楼层
确保路径包括可执行文件的名称(inkscape.exe)
回复

使用道具 举报

4

主题

37

帖子

98

积分

注册会员

Rank: 2

积分
98
发表于 2018-9-27 15:33:53 | 显示全部楼层
当我在subprocess模块中遇到这个问题时,我发现‘args’(subprocess. popen())中的第一个条目(subprocess. popen()的第一个参数)我需要将参数列表中的可执行文件设置为我的可执行文件的完整路径。
app = 'app.exe'
appPath = os.path.join(BIN_DIR, app)

commandLine = [app, 'arg1', 'arg2']
process = subprocess.Popen(commandLine, executable=appPath)
回复

使用道具 举报

22

主题

107

帖子

266

积分

中级会员

Rank: 3Rank: 3

积分
266
发表于 2018-9-27 15:37:37 | 显示全部楼层
或者,如果你的模块不工作,你可以使用«subprocess»模块:
  1. import subprocess, os, time
  2. process = subprocess.Popen("somecommand", shell=True)
  3. n = 0
  4. while True:
  5.     if not process.poll():
  6.         print('The command is running...')
  7.         if n >= 10:
  8.             pid = process.pid()
  9.             os.kill(pid, 9) # 9 = SIGKILL
  10.     else:
  11.         print('The command is not running..')
  12.     n += 1
  13.     time.sleep(1)
复制代码
回复

使用道具 举报

4

主题

33

帖子

88

积分

注册会员

Rank: 2

积分
88
发表于 2018-9-27 15:43:24 | 显示全部楼层
你是否指定要传递给Popen (argv中的第一项)的可执行文件的完整路径?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表