Python Forum
Cannot import list from another module? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Cannot import list from another module? (/thread-24515.html)



Cannot import list from another module? - t4keheart - Feb-17-2020

Hi guys,
I'm hoping this is something simple I'm missing... but for some reason I'm unable to import a list from another module, the contents always show as nothing.

module 1: checks a database and populates a job number into a list

#!C:\Program Files\Python37\python.exe
from logger import Logger
from configparser import ConfigParser
from connectDb import connectDb, disconnectDb
import time

config = ConfigParser()
config.read('config.ini')

q = []
jobsInQueue=0
lastSent=''
pullId=config.get('QUERY', 'pullId')
module='[Job Queue]'

def jobQueue():
    global lastSent, jobsInQueue, q
    cnxn=connectDb()
    cursor=cnxn.cursor()
    cursor.execute(pullId)
    r=cursor.fetchone()
    lastSent=r
    print(module + ' module started.')
    
    while True:
        cursor.execute(pullId)
        r=cursor.fetchone()
        s=r
        if r!=lastSent:
            strips(s)
            lastSent=s
            jobsInQueue+=1
            q.append(s)
            print('New outbound sms detected, placed in queue...')
            print(str(jobsInQueue) + ' total jobs in queue.')
            Logger.sendLog('Job ' + str(s) + ' detected and placed in queue', 0)
            time.sleep(1)
        else:
            time.sleep(1)
            pass
Module 2, just would like to import the list (and count of items in the list) so I can use it as a queue... however, the list and other object always show as empty and 0
from jobQueue import q, jobsInQueue
import time

def send():
    while True:
        print(jobsInQueue)
        print(q)
        time.sleep(4)

I forgot to mention that yes both modules/functions are called but I'm doing it via multiprocessing... which i suspect has to do with the issue in why I can't pass the object between the processes.


RE: Cannot import list from another module? - t4keheart - Feb-17-2020

Found that I'll need to use an actual queue and share it between the processes. Might as well go back to the drawing board on this one completely and re-create with classes so I don't have to use global