Python Forum
Cannot import list from another module?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot import list from another module?
#1
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.
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  is import cointegration_analysis a recognized module mitcht33 1 385 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 1,260 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 680 Aug-06-2023, 01:09 AM
Last Post: aupres
  import module error tantony 5 3,362 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Import a module one step back of the path prathampatel9 1 1,036 Sep-21-2022, 01:34 PM
Last Post: snippsat
  Import a module for use in type hint? Milosz 0 1,455 Nov-08-2021, 06:49 PM
Last Post: Milosz
  Can't install nor import delorean module Tek 3 2,741 Oct-27-2021, 03:32 AM
Last Post: Tek
  import module with syntax error Skaperen 7 5,161 Jun-22-2021, 10:38 AM
Last Post: Skaperen
  'urllib3' Module not found when import 'requests' spanz 5 9,961 Jan-06-2021, 05:57 PM
Last Post: snippsat
  Problem with Flask Bcrypt import module marcello86 2 5,597 Aug-31-2020, 08:10 PM
Last Post: marcello86

Forum Jump:

User Panel Messages

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