Skip to content

Call getJobs in thread: PyEval_RestoreThread: NULL tstate #43

Description

@anxuae

Calling the function getJobs in a thread crash the application.
It seems that some functions are not thread-safe. How can I handle it?

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "test3.py", line 19, in print_jobs
    "job-uri", "job-state"])))
cups.IPPError: (1280, 'No such file or directory')

Fatal Python error: PyEval_RestoreThread: NULL tstate

Current thread 0x76f6cad0 (most recent call first):
  File "test3.py", line 34 in <module>
Abandon

I'm using the following script to reproduce it:

import threading
import time
import cups
import os.path as osp

FILENAME = "test3.py"
RUN = True

def print_jobs():
    time.sleep(1)
    while RUN == True:
        time.sleep(0.1)
        print("Jobs count:", len(conn.getJobs(my_jobs=True, requested_attributes=["job-id", "job-name",
                                                                                  "job-uri", "job-state"])))

THREAD = threading.Thread(target=print_jobs)
THREAD.daemon = True

# Create a CUPS connection
conn = cups.Connection()
name = conn.getDefault()

try:
    THREAD.start()
    while True:
        time.sleep(0.1)
        conn.printFile(name, FILENAME, osp.basename(FILENAME), {})

except KeyboardInterrupt:
    print("Stop")

finally:
    print("Cancel tasks")
    RUN = False
    conn.cancelAllJobs(name)
    THREAD.join()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions