Python Forum
function/nonetype object is not iterable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function/nonetype object is not iterable
#1
Hi all,

I am getting error "functools.partial object not iterable". I google searched this issue and have read multiple answers about this issue but still cannot figure out how to rewrite my code to get my subprocess to run.

import time
import sched
import subprocess
from functools import partial

s = sched.scheduler(time.time, time.sleep)

def delay(set_time):
    s.enter(set_time, 1, pass_func)
    s.run()

def pass_func():
    pass

def emptyKeg():
    print("A start: ", time.time())
    delay(5)
    print("A after 5: ", time.time())

def emptyGlass():
    print("B start: ", time.time())
    delay(5)
    print("B after 5: ", time.time())

cycle = [emptyKeg(), emptyGlass()]

def runCycle(cycle):
    for func in cycle:
        try:
            func
        except ValueError: 
            break

sub = subprocess.Popen(partial(runCycle, cycle))


while True:
    pass
I've also rewritten the program to be simpler, without using partial and I get error "nonetype object is not iterable". Again, I've read lot about this topic but still not sure what I am doing wrong.

import time
import sched
import subprocess


s = sched.scheduler(time.time, time.sleep)


def delay(set_time):
    s.enter(set_time, 1, pass_func)
    s.run()


def pass_func():
    pass


def emptyKeg():
    print("A start: ", time.time())
    delay(5)
    print("A after 5: ", time.time())


def emptyGlass():
    print("B start: ", time.time())
    delay(5)
    print("B after 5: ", time.time())


def runCycle():
   emptyKeg()
   emptyGlass()


sub = subprocess.Popen(runCycle())


while True:
    pass
Reply
#2
please post complete unmodified error traceback
Reply
#3
Ok my bad.

First traceback:
Error:
Traceback (most recent call last): File "C:/Users/Darwin/mu_code/sampleSubprocess2.py", line 41, in <module> sub = subprocess.Popen(partial(runCycle, cycle)) File "C:\Users\Darwin\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\Darwin\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1247, in _execute_child args = list2cmdline(args) File "C:\Users\Darwin\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 549, in list2cmdline for arg in map(os.fsdecode, seq): TypeError: 'functools.partial' object is not iterable
Process finished with exit code 1


Second traceback:
Error:
Traceback (most recent call last): File "C:/Users/Darwin/mu_code/sampleSubprocess2.py", line 36, in <module> sub = subprocess.Popen(runCycle()) File "C:\Users\Darwin\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\Darwin\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1247, in _execute_child args = list2cmdline(args) File "C:\Users\Darwin\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 549, in list2cmdline for arg in map(os.fsdecode, seq): TypeError: 'NoneType' object is not iterable
Process finished with exit code 1
Reply
#4
I'm not sure what your intent is on line 35 (different from error traceback (35 vs 36)) (second code) as nothing is returned from runCycle()
Reply
#5
cycle = [emptyKeg(), emptyGlass()] # this is [None, None]
# Maybe
# cycle = [emptyKeg, emptyGlass]
 
def runCycle(cycle):
    for func in cycle:
        try:
            func  # Does not call function.  Maybe func()
        except ValueError: 
            break
Reply
#6
Cool, changed my use of parenthesis like deanhystad suggested.

Commenting out my subprocess code, this script works now.

import time
import sched
import subprocess
from functools import partial

s = sched.scheduler(time.time, time.sleep)


def delay(set_time):
    s.enter(set_time, 1, pass_func)
    s.run()


def pass_func():
    pass


def emptyKeg():
    print("A start: ", time.time())
    delay(5)
    print("A after 5: ", time.time())


def emptyGlass():
    print("B start: ", time.time())
    delay(5)
    print("B after 5: ", time.time())


def runCycle(cycle):
    for func in cycle:
        try:
            func()
        except ValueError:  
            break

cycleRun = [emptyKeg, emptyGlass]

runCycle(cycleRun)    # new line to replace the broken code below

#sub = subprocess.Popen(partial(runCycle, cycleRun))  # broken, not sure whats wrong

while True:
    pass
Now I just have to figure out how to make subprocess work.

I suppose I should add that I was previously trying to use a thread to run my function runCycle. But now I'm trying to use subprocess instead of thread because subprocess has a method kill() that will quickly stop the code.

Hmm maybe Popen is not the best fit to run a function. I've got to do more reading on this. Thanks everyone for helping with my poor understanding of python!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 679 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 920 Aug-24-2023, 05:14 PM
Last Post: snippsat
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,385 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,213 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  TypeError: 'NoneType' object is not subscriptable syafiq14 3 5,166 Sep-19-2022, 02:43 PM
Last Post: Larz60+
Question how to solve `'TypeError: 'int' object is not iterable`? netanelst 2 1,524 May-24-2022, 12:03 PM
Last Post: deanhystad
  AttributeError: 'function' object has no attribute 'metadata 3lnyn0 5 4,522 Mar-28-2022, 04:42 PM
Last Post: Larz60+
  AttributeError: 'NoneType' object has no attribute 'group' MaartenRo 3 4,588 Jan-02-2022, 09:53 AM
Last Post: snippsat
  AttributeError: 'NoneType' object has no attribute 'group' MaartenRo 3 2,559 Jan-01-2022, 04:16 PM
Last Post: MaartenRo
  Getting 'NoneType' object has no attribute 'find' error when WebScraping with BS Franky77 2 5,166 Aug-17-2021, 05:24 PM
Last Post: Franky77

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020