dbader / dbader/schedule

How to pass a value when using threading?

Open
#507 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
12.3k
Forks
999
PR merge metrics
No merged PRs in 30d

Description

If I have some functions very similar to the documentation:

```
def job(faces):
print("I'm running on thread %s" % threading.current_thread())
pload = {'face_count':num_faces}
r = requests.post('https://httpbin.org/post',data=pload)
print(r.text)

def run_threaded(job_func, faces):
job_thread = threading.Thread(target=job_func)
job_thread.start()
```

How do I pass a value to the `run_threaded` function? Looking to pass an int value called `faces`

```
import threading
import time
import schedule
import requests

def job(faces):
print("I'm running on thread %s" % threading.current_thread())
pload = {'face_count':num_faces}
r = requests.post('https://httpbin.org/post',data=pload)
print(r.text)

def run_threaded(job_func, faces):
job_thread = threading.Thread(target=job_func)
job_thread.start()

num_faces = 0
schedule.every(30).seconds.do(run_threaded, num_faces)

try:
while True:
schedule.run_pending()

```

This will error out, any tips appreciated:
```
Traceback (most recent call last):
File "C:\Users\bbartling\OneDrive - Slipstream\Desktop\LBS\openCvTesting\test.py", line 37, in
schedule.run_pending()
File "C:\Python39\lib\site-packages\schedule\__init__.py", line 780, in run_pending
default_scheduler.run_pending()
File "C:\Python39\lib\site-packages\schedule\__init__.py", line 100, in run_pending
self._run_job(job)
File "C:\Python39\lib\site-packages\schedule\__init__.py", line 172, in _run_job
ret = job.run()
File "C:\Python39\lib\site-packages\schedule\__init__.py", line 661, in run
ret = self.job_func()
TypeError: run_threaded() missing 1 required positional argument: 'faces'
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Review the run_threaded and job entry points, along with the schedule.every(...).do(...) call shown in the issue. Check how scheduled job arguments are passed and how threading.Thread invokes its target. Done when the documented example accepts faces without the missing-argument error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.